ImgLib2: Changing pixels of a converted image

Hi all,

I can create an ARGBType image like this:

ImageJ ij = new ImageJ();
RandomAccessibleInterval<ARGBType> img = ij.op().create().img(new FinalInterval(10, 10), new ARGBType());
Cursor<ARGBType> cursor = Views.iterable(img).cursor();
while(cursor.hasNext()) {
	cursor.next().set(ARGBType.rgba(255,0,0,255));
}
ImageJFunctions.show(img, "red");

… and it shows me a red image. But this shows be a black image:

ImageJ ij = new ImageJ();
RandomAccessibleInterval<IntType> img = ij.op().create().img(new FinalInterval(10, 10), new IntType());
Converter<IntType, ARGBType> converter = (i, o) -> o.set(ARGBType.rgba(0,0,0,0))};
RandomAccessibleInterval<ARGBType> converted = Converters.convert(img, converter, new ARGBType());
Cursor<ARGBType> cursor = Views.iterable(converted).cursor();
while(cursor.hasNext()) {
	cursor.next().set(ARGBType.rgba(255,0,0,255));
}
ImageJFunctions.show(converted, "red");

Can someone explain to me why this is not red as well?

4 Likes

Hi @frauzufall,

This is what imglib3 should be all about :wink:

In short, this is not possible now because calling the set method of a converted type doesn’t do anything, because the ARGBType is virtual.

This line:

RandomAccessibleInterval<ARGBType> converted = Converters.convert(img, converter, new ARGBType());

allocates no new memory. It just makes an object that wraps the img and converter variables.

This thread has some discussion on this same issue:


In particular, @hanslovsky’s reply.

John

4 Likes

Alright, thank you for pointing me to this thread!

1 Like

@frauzufall if you actually want to write into the source of a converted image, you can use the SamplerConverter . I do not know if there is an implementation for your particular use case, but the ARGBChannelSamplerConverter might help get you started.

1 Like