Get pixel data from ImgPlus

Before I present my problem, I’m new to knime, so please don’t be too rude :slight_smile:
I got an ImageReader (Table) node, which downloads images via URLs from a webserver. With this images I would like to create a video (.mp4).
I tried with a JavaSnippet, but the ouput data from my ImageReader is a table with ImgPlus files and I can’t work with them, because it’s unpossible for me to access the pixels in there, or even to convert it in a standart Java “Image” Object.
So here’s my question, is it possible to find a workaround for this problem? How I said, i want to create a video, either with standard knime nodes or with the JavaSnippet node.
So please, if anybody know how to get an Image Object from the ImgPlus data or to create a video with ImgPlus data, comment your solutions.

Thanks,
spenger_knime

@spenger_knime

Before I present my problem, I’m new to knime, so please don’t be too rude

Don’t worry, we are very nice :slight_smile:, to create an movie out of a series of images you can use a Transpose node followed by a Merger node, to transform the images into one image volume.
Then you can use the Image Writer node to write the image to disk. We currently do not support .mp4, but you can write them as .avi, you probably want to use a tool like ffmpeg to compress the resulting videos, as they are not compressed and rather large.

best,
Gabriel

PS: Always feel free to ask more questions :slight_smile:

I tried it like this, but my goal is create a .mp4 file inside the workflow and export it afterwards. My actual problem is, that i cannot access the image data itself inside the JavaSnippet. The input value is a table with .png files, which comes from a “ImgPlus to PNG” node. But inside the Snippet, the only avaible data type is “String”.
Can you help me here?

You can actually use ImgPlus cells directly in the JavaSnippet node,
there you can make use of Imglib2 to get access to the pixeldata. I have attached a simple workflow that shows how to get pixel values from a ByteType image, you will need to adapt the code to your needs but it should give you a start. Feel free to ask follow up questions if you need any additional help.
access pixels.knwf (7.6 KB)
best,
Gabriel

I tried to implement your snippet in my existing code, but the error i got after doing this is as following:

net.imglib2.view.IntervalView cannot be cast to net.imglib2.Cursor

Maybe any ideas behind this?

PS: After trying to compile your script without doing any changes, there is also an error:
WARN Java Snippet 0:3 Evaluation of java snippet failed for row “img_BYTETYPE_net.imglib2.img.array.ArrayImgFactory@1f625ffd_0”. The exception is caused by line 38 of the snippet. Exception message:2

Oh I see that there is still a bug in my code, lines 45-46 should be :

IntervalView<ByteType> img = Views.hyperSlice(c_Img, 2,i);
Cursor<ByteType> c = img.cursor();

In that script I assume that the image is 3 dimensional and iterate over that third dimension, if you input a 2d image it will not work, it seems like I miss configured the Image Generator to output 2d images in the version of the workflow I exported. You can easily fix this by setting e.g. the upper bound of the Size Time parameter to any value larger 0.

best,
Gabriel