Skip to main content

[JAI] Creating ROI

3 replies [Last post]
Anonymous

Hi,

I'm trying to create a ROI in this way:

RenderedImage renderedImage = javax.imageio.ImageIO.read(new
File("C:\\Users\\maciek\\Desktop\\Roi.png"));
ROI roi = new ROI(renderedImage, 1);

Roi.png <- is a png image saved to a disk (image after preprocessing, it has
one big white region and I'm trying to reate roi to descripe this region).

I'm getting on output this:

Exception in thread "main" java.lang.IllegalArgumentException: Can construct
from single-banded images only.

Can somebody help me?

Best regards
Maciek
[att1.html]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Rafael Santos

Just a guess:
>
> Roi.png <- is a png image saved to a disk (image after preprocessing,
> it has one big white region and I'm trying to reate roi to descripe
> this region).
>
> I'm getting on output this:
>
> Exception in thread "main" java.lang.IllegalArgumentException: Can
> construct from single-banded images only.
>
A PNG image, even with only black and white pixels, may represent a
color image, which will have three bands. Try and save it as a
single-banded image and see whether the problem continues.

Rafael
[att1.html]

Maciek Owczarek

>
>
> A PNG image, even with only black and white pixels, may represent a color
> image, which will have three bands. Try and save it as a single-banded image
> and see whether the problem continues.
>
> Rafael
>

Is there any special way for saveing BufferedImage as a single-banded image?
I tried simpley changed the output format for jpg etc. but it doesn't work.
What exacly is single - banded image?

Maciek
[att1.html]

Maciek Owczarek

After some while I get this:
-------------------------------------------------------------------------------------------------------------------------------------------------
wyjscie = new File("C:\\Users\\maciek\\Desktop\\Roi.png");
try {
ImageIO.write(in, "png", wyjscie);
} catch (IOException ex) {
Logger.getLogger(ImageMath.class.getName()).log(Level.SEVERE,
null, ex);
}

RenderedImage renderedImage = javax.imageio.ImageIO.read(new
File("C:\\Users\\maciek\\Desktop\\Roi.png"));
SampleModel sampleModel =
RasterFactory.createBandedSampleModel(DataBuffer.TYPE_BYTE,in.getWidth(),in.getHeight(),1);
TiledImage tiledImage = new
TiledImage(0,0,in.getWidth(),in.getHeight(),0,0,sampleModel,null);

tiledImage.set(renderedImage);

JAI.create("filestore",tiledImage,"C:\\Users\\maciek\\Desktop\\singlebin.png","PNG");

-------------------------------------------------------------------------------------------------------------------------------------------------
Where
Roi.pnh is <- http://img28.imageshack.us/img28/186/roi.png
and my single-banded image is <-
http://img684.imageshack.us/img684/5680/singlebin.png

as you can see something is wrog, very wrog. Please help and indicate where
I made a mistake.

Maciek
[att1.html]