Skip to main content

jp2000 image loading

5 replies [Last post]
sdelamare
Offline
Joined: 2006-03-21

Hello everyBody

I have a small problem with JP2000 files.
I would like to load a JP2000 file, and store it in tiff format file.
So, I will attach my snippet code.
The result is a tiff file but almost black everywhere, except at the top of the image.

please, could you tell me what is wrong in my code ??

"
protected RenderedOp loadJPEG2000(String pathFile_p)
throws Exception,FileNotFoundException,IOException {
RenderedOp imageToReturn_l = null;
ParameterBlockJAI paramsBlockJAI_l = null;
J2KImageReadParam j2k_l = null;
FileImageInputStream fiis_l =null;
Iterator iter_l = null;
ImageReader jp2ir = null;

try {
j2k_l = new J2KImageReadParam();
paramsBlockJAI_l = new ParameterBlockJAI("ImageRead","rendered");
fiis_l = new FileImageInputStream(new File (pathFile_p));
paramsBlockJAI_l.setParameter("Input", fiis_l);

paramsBlockJAI_l.setParameter("ReadParam", j2k_l);
iter_l = ImageIO.getImageReadersBySuffix("JP2");
if (iter_l.hasNext()) {
jp2ir = (ImageReader) iter_l.next();
}
else {
throw new Exception("Cannot open a JPEG2000 reader..");

}
paramsBlockJAI_l.setParameter("Reader", jp2ir);
imageToReturn_l = JAI.create("ImageRead", paramsBlockJAI_l);
}
catch (FileNotFoundException e) {
throw e;
}
catch (IOException e) {
throw e;
}
return imageToReturn_l;
}

public static void fileStoreTiff(PlanarImage imageIn_p,String pathOut_p) {
ParameterBlockJAI pbJAI = new ParameterBlockJAI ("filestore");
pbJAI.setParameter("filename",pathOut_p);
pbJAI.setParameter("format", "TIFF");
pbJAI.setSource(imageIn_p, 0);
JAI.create("filestore",pbJAI);
pbJAI.removeSources();
}

public static void main(String[] args) {

RenderedOp imageOp_l;
imageOp_l = loadJPEG2000(myPathIn_l);
fileStoreTiff( imageOp_l , pathOut_l);
}
"

Thanks !!!!

Sandrine.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bpb
Offline
Joined: 2004-06-23

At a glance your code looks OK. What is the bit depth of the image? How are you viewing the resultant TIFF?

Brian

> Hello everyBody
>
> I have a small problem with JP2000 files.
> I would like to load a JP2000 file, and store it in
> tiff format file.
> So, I will attach my snippet code.
> The result is a tiff file but almost black
> everywhere, except at the top of the image.
>
> please, could you tell me what is wrong in my code
> ??
>
> "
> protected RenderedOp loadJPEG2000(String pathFile_p)
> throws Exception,FileNotFoundException,IOException
> n {
> RenderedOp imageToReturn_l = null;
> ParameterBlockJAI paramsBlockJAI_l = null;
> J2KImageReadParam j2k_l = null;
> FileImageInputStream fiis_l =null;
> Iterator iter_l = null;
> ImageReader jp2ir = null;
>
> try {
> j2k_l = new J2KImageReadParam();
> paramsBlockJAI_l = new
> new ParameterBlockJAI("ImageRead","rendered");
> fiis_l = new FileImageInputStream(new File
> ile (pathFile_p));
> paramsBlockJAI_l.setParameter("Input", fiis_l);
>
> paramsBlockJAI_l.setParameter("ReadParam",
> m", j2k_l);
> iter_l = ImageIO.getImageReadersBySuffix("JP2");
> if (iter_l.hasNext()) {
> jp2ir = (ImageReader) iter_l.next();
> }
> else {
> throw new Exception("Cannot open a JPEG2000
> 2000 reader..");
>
> }
> paramsBlockJAI_l.setParameter("Reader", jp2ir);
> imageToReturn_l = JAI.create("ImageRead",
> d", paramsBlockJAI_l);
> }
> catch (FileNotFoundException e) {
> throw e;
> }
> catch (IOException e) {
> throw e;
> }
> return imageToReturn_l;
> }
>
>
>
> public static void fileStoreTiff(PlanarImage
> e imageIn_p,String pathOut_p) {
> ParameterBlockJAI pbJAI = new
> JAI pbJAI = new ParameterBlockJAI ("filestore");
> pbJAI.setParameter("filename",pathOut_p);
> pbJAI.setParameter("format", "TIFF");
> pbJAI.setSource(imageIn_p, 0);
> JAI.create("filestore",pbJAI);
> pbJAI.removeSources();
> }
>
> public static void main(String[] args) {
>
> RenderedOp imageOp_l;
> imageOp_l = loadJPEG2000(myPathIn_l);
> fileStoreTiff( imageOp_l , pathOut_l);
> }
> "
>
>
> Thanks !!!!
>
> Sandrine.

sdelamare
Offline
Joined: 2006-03-21

Hello

I visualize the tiff with The Gimp and IrFanView.
I would like to send you the image jp2000, but I can't attach a file to this mail ... :-(

Sandrine.

Message was edited by: sdelamare

Brian Burkhalter

Send it directory.

Brian

On Tue, 5 Dec 2006, jai-imageio@javadesktop.org wrote:

> Hello
>
> I visualize the tiff with The Gimp and IrFanView.
> I would like to send you the image jp2000, but I can't attach a file to this mail ... :-(
>
> Sandrine.
> [Message sent by forum member 'sdelamare' (sdelamare)]
>
> http://forums.java.net/jive/thread.jspa?messageID=182702
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

sdelamare
Offline
Joined: 2006-03-21

ok
I did it :-)

thanks

Sandrine

Brian Burkhalter

Sandrine,

I received the image and was able to display all 5 levels using both the
jai-imageio java and jai-imageio native JPEG2000 readers.

Do you have a complete, self-contained test case (not a snippet) demonstrating
the problem you originally posted about?

Thanks,

Brian

On Thu, 7 Dec 2006, jai-imageio@javadesktop.org wrote:

> ok I did it :-)

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net