Skip to content

Add method Intervals.positions( Interval ) to allow localizing LoopBuilder loops.#279

Merged
maarzt merged 2 commits intomasterfrom
add-intervals-positions
Jan 14, 2020
Merged

Add method Intervals.positions( Interval ) to allow localizing LoopBuilder loops.#279
maarzt merged 2 commits intomasterfrom
add-intervals-positions

Conversation

@maarzt
Copy link
Copy Markdown
Contributor

@maarzt maarzt commented Jan 10, 2020

It's hard to get pixel positions in a LoopBuilder loop. This PR implements the solution (1) suggested here #273 (comment).

The method Intervals.positions(Interval) returns an image where each pixel value equals the position of the pixel. (The new method does the same as the existing method Localizables.randomAccessibleInterval(Interval), but the name is much nicer.)

This allows the get pixel positions in LoopBuilder:

LoopBuilder.setImages( Intervals.positions( image ), image ).forEachPixel(
    ( position, pixel ) -> {
        int x = position.getIntPosition( 0 );
        int y = position.getIntPosition( 1 );
        pixel.set( x * x + y * y );
    }
)

The method is the same as the already existing method
Localizables.randomAccessibleInterval() but has a much
better name.

This method allows to write LoopBuilder loops, that
use the pixel coordinates.

LoopBuilder.setImages( Intervals.positions( image ), image ).forEachPixel(
    ( position, pixel ) -> {
        int x = position.getIntPosition( 0 );
        int y = position.getIntPosition( 1 );
        pixel.set( x * x + y * y );
    }
)
@maarzt maarzt self-assigned this Jan 10, 2020
@maarzt maarzt merged commit 2222a50 into master Jan 14, 2020
@tpietzsch tpietzsch deleted the add-intervals-positions branch March 20, 2020 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant