I want to do an overlay operation with two images. The number of bands and the data type of these images need to be the same, so I can perform the overlay operation. Therefore I'm using a FormatDescriptor
to change the data type of one image to that of the other. But now the image is all white.
Is that normal? Or do I have an error in the FormatDescriptor
?
Below is the code for the reformatting:
RenderedImage finalImage = loadTiles(i, columns, rows); // Format Image so that the data type matches that of the overlay finalImage = FormatDescriptor.create(finalImage, overlay.getSampleModel().getDataType(), null); images.add(finalImage); columns = roundUp(columns, 2); rows = roundUp(rows, 2);
Thank you for your help.
EDIT I tried formatting the overlay so it matches the data type of the image. That way the image is displayed correctly, but the overlay is completly black.
The normal data types are as follows:
image: data type = 1 (ushort)
overlay: data type = 0 (byte)
EDIT I also tried reformatting the image to every other data type. And everytime I got the same result. The image was all white. Except when I tried formatting to short. Then I got NullPointerException
.
I have no idea, what I'm doing wrong. I have found many different examples of using the Format Operation and I used it the same way. But when I get a white image when reformatting, what is the point of using the Format Operation? Is there another way to change the data type of the image, so it matches that of the overlay?
Ok, I figured out a different way to change the datatype of the image. It is possible using a
LookupTableJAI
. Below is the code I used to convert the image: