imglib / imglib2

A generic next-generation Java library for image processing
http://imglib2.net/
Other
302 stars 93 forks source link

Extended ConvertedRandomAccessible fails if source of ConvertedRandomAccessibleInterval is not Extended #82

Open dietzc opened 9 years ago

dietzc commented 9 years ago

See below. If this is a bug, the desired behaviour would be, that the converter isn't called on out of bounds values in this situation (as our out-of-bounds strategy defines the value in this case).

@Test
public void testExtendedConvertedImg() {

    RandomAccessibleInterval<BitType> converted = Converters.convert(
            (RandomAccessibleInterval<ByteType>) ArrayImgs.bytes(100, 100),
            new Converter<ByteType, BitType>() {

                @Override
                public void convert(ByteType input, BitType output) {
                    output.setReal(input.get());
                }
            }, new BitType());

    IntervalView<BitType> extendBorder = Views.interval(Views.extendBorder(converted), converted);

    RandomAccess<BitType> randomAccess = extendBorder.randomAccess();
    randomAccess.setPosition(new long[] { -10, -10 });
    randomAccess.get().get();
}
dietzc commented 9 years ago

This one I don't understand after your recent explanation @tpietzsch. See comment.

@Test
public void testExtendedConvertedImg() {

    RandomAccessibleInterval<BitType> input = Converters.convert(
            (RandomAccessibleInterval<ByteType>) ArrayImgs.bytes(100, 100),
            new Converter<ByteType, BitType>() {

                @Override
                public void convert(ByteType input, BitType output) {
                    output.setReal(input.get());
                }
            }, new BitType());

    IntervalView<BitType> extendBorder = Views.interval(
            Views.extendBorder(input), input);

    /**
     * I don't understand the API here. if this doesn't work in the 3 lines
     * below, why does it work in the neighborhood case?
     */
    RandomAccess<BitType> randomAccess = extendBorder.randomAccess();
    randomAccess.setPosition(new long[] { -10, -10 });
    randomAccess.get().get();

    Shape rectangle = new RectangleShape(5, false);

    for (Neighborhood<BitType> n : rectangle.neighborhoods(extendBorder)) {

        for (BitType type : n) {
            type.get();
        }

    }
}
axtimwalde commented 4 years ago

Is this still relevant? Sounds more like a problem of unsynchronized expectations and outcomes than a bug?