Skip to main content

WrittableRasters and PlanarImages

5 replies [Last post]
sportinguista
Offline
Joined: 2010-05-30

Hi,

Having this declaration of MyImage class in order to work with multiband TIFF images:

public class MyImage {

private int nbands, height, width;
private SampleModel sampleModel;
private PlanarImage pi;
private WritableRaster wr; //for mousemoved display info, and set ang get pixel values
private String path; //file path
private PlanarImage displayImage=null; // 8 bit PlanarImage for displaying non-byte "pi"-images

public MyImage(String file) {

this.path = file;
pi = JAI.create("imageread", file);
width = pi.getWidth();
height = pi.getHeight();
sampleModel = pi.getSampleModel();
nbands = sampleModel.getNumBands();
wr = (WritableRaster) pi.getData();
}

I want to make double operations in its byte data. Like this:

public void landsatCalibration(double [][] param){
}
---See next post, please---

First -> I would like you to give me your opinion of MyImage class efficiency. I need PlanarImage for convolution operations, and WrittableRaster for pixel opperations. I display my images with DisplayJAI.

Second-> In landsatCalibration method, it always gives me error in wr = pi.copyData(); why do you think? (shown below)

Thank you!!

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Cannot construct DataBuffer.
at com.sun.media.jai.util.DataBufferUtils.constructDataBuffer(DataBufferUtils.java:132)
at com.sun.media.jai.util.DataBufferUtils.createDataBufferDouble(DataBufferUtils.java:293)
at javax.media.jai.ComponentSampleModelJAI.createDataBuffer(ComponentSampleModelJAI.java:274)
at javax.media.jai.RecyclingTileFactory.createTile(RecyclingTileFactory.java:389)
at javax.media.jai.PlanarImage.createWritableRaster(PlanarImage.java:1982)
at javax.media.jai.PlanarImage.copyData(PlanarImage.java:2319)
at javax.media.jai.PlanarImage.copyData(PlanarImage.java:2279)
at javax.media.jai.RenderedOp.copyData(RenderedOp.java:2285)
at imagenessatelite.Imagen.calibracionLandsat(Imagen.java:340)
at imagenessatelite.VentanaParametrosCalibracion.jButton3ActionPerformed(VentanaParametrosCalibracion.java:445)
at imagenessatelite.VentanaParametrosCalibracion.access$100(VentanaParametrosCalibracion.java:21)
at imagenessatelite.VentanaParametrosCalibracion$2.actionPerformed(VentanaParametrosCalibracion.java:106)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Reply viewing options

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

As to efficiency, if it's good enough then it's good enough. ;-)

You could potentially speed it up by writing your own operator that does
all the math operations (and even the double conversion) at once... thus
avoiding several extra loops. But only do that if you can demonstrate
that this code is causing you performance issues. It's not worth it
otherwise. If you're doing a convolution, then I doubt that the three
arithmetic operators + the format will even be noticeable by comparison.

-Bob

jai-interest@javadesktop.org wrote:
> Hi,
>
> Having this declaration of MyImage class in order to work with multiband TIFF images:
>
> public class MyImage {
>
> private int nbands, height, width;
> private SampleModel sampleModel;
> private PlanarImage pi;
> private WritableRaster wr; //for mousemoved display info, and set ang get pixel values
> private String path; //file path
> private PlanarImage displayImage=null; // 8 bit PlanarImage for displaying non-byte "pi"-images
>
> public MyImage(String file) {
>
> this.path = file;
> pi = JAI.create("imageread", file);
> width = pi.getWidth();
> height = pi.getHeight();
> sampleModel = pi.getSampleModel();
> nbands = sampleModel.getNumBands();
> wr = (WritableRaster) pi.getData();
> }
>
> I want to make double operations in its byte data. Like this:
>
> public void landsatCalibration(double [][] param){
> }
> ---See next post, please---
>
> First -> I would like you to give me your opinion of MyImage class efficiency. I need PlanarImage for convolution operations, and WrittableRaster for pixel opperations. I display my images with DisplayJAI.
>
> Second-> In landsatCalibration method, it always gives me error in wr = pi.copyData(); why do you think? (shown below)
>
> Thank you!!
>
>
>
> Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Cannot construct DataBuffer.
> at com.sun.media.jai.util.DataBufferUtils.constructDataBuffer(DataBufferUtils.java:132)
> at com.sun.media.jai.util.DataBufferUtils.createDataBufferDouble(DataBufferUtils.java:293)
> at javax.media.jai.ComponentSampleModelJAI.createDataBuffer(ComponentSampleModelJAI.java:274)
> at javax.media.jai.RecyclingTileFactory.createTile(RecyclingTileFactory.java:389)
> at javax.media.jai.PlanarImage.createWritableRaster(PlanarImage.java:1982)
> at javax.media.jai.PlanarImage.copyData(PlanarImage.java:2319)
> at javax.media.jai.PlanarImage.copyData(PlanarImage.java:2279)
> at javax.media.jai.RenderedOp.copyData(RenderedOp.java:2285)
> at imagenessatelite.Imagen.calibracionLandsat(Imagen.java:340)
> at imagenessatelite.VentanaParametrosCalibracion.jButton3ActionPerformed(VentanaParametrosCalibracion.java:445)
> at imagenessatelite.VentanaParametrosCalibracion.access$100(VentanaParametrosCalibracion.java:21)
> at imagenessatelite.VentanaParametrosCalibracion$2.actionPerformed(VentanaParametrosCalibracion.java:106)
> at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
> at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
> at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
> at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
> at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
> at java.awt.Component.processMouseEvent(Component.java:6263)
> at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
> at java.awt.Component.processEvent(Component.java:6028)
> at java.awt.Container.processEvent(Container.java:2041)
> at java.awt.Component.dispatchEventImpl(Component.java:4630)
> at java.awt.Container.dispatchEventImpl(Container.java:2099)
> at java.awt.Component.dispatchEvent(Component.java:4460)
> at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
> at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
> at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
> at java.awt.Container.dispatchEventImpl(Container.java:2085)
> at java.awt.Window.dispatchEventImpl(Window.java:2478)
> at java.awt.Component.dispatchEvent(Component.java:4460)
> at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
> at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
> at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
> at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
> at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
> [Message sent by forum member 'sportinguista']
>
> http://forums.java.net/jive/thread.jspa?messageID=477903
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>

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

sportinguista
Offline
Joined: 2010-05-30

okey thanks!

I´ll work with float values then. I´m trying to make my JAI-tool a little similar to some ENVI functions, so I watch how ENVI works to implement some similar :P

I´ve seen that calibrating in ENVI produces float data images. So I´ll continue with this.

And just out of curiosity, why loading and working with images in ENVI is so fast? What did they use for the implementation?

Thank you!

sportinguista
Offline
Joined: 2010-05-30

public void landsatCalibration(double[][] ){

...............create subtractThis, multiplyBy, and addThis arrays........

// Let's convert pi data type. Originally TYPE_BYTE
ParameterBlock pbConvert = new ParameterBlock();
pbConvert.addSource(pi);
pbConvert.add(DataBuffer.TYPE_DOUBLE);
pi = JAI.create("format", pbConvert);

ParameterBlock pbSub = new ParameterBlock();
pbSub.addSource(pi);
pbSub.add(subtractThis); // double type block with constants
pi = JAI.create("subtractconst", pbSub, null);

ParameterBlock pbMult = new ParameterBlock();
pbMult.addSource(pi);
pbMult.add(multiplyBy); // double type block with constants
pi = JAI.create("multiplyconst", pbMult, null);

ParameterBlock pbAdd = new ParameterBlock();
pbAdd.addSource(pi);
pbAdd.add(addThis); // double type block with constants
pi = JAI.create("AddConst", pbAdd, null);

//sets wr and sampleModel attibutes with new data

sampleModel = pi.getSampleModel();
wr = pi.copyData(); //or (WrittableRaster)pi.getData();
}

sportinguista
Offline
Joined: 2010-05-30

Nobody?

I´ve been watching error traces and I found:

Caused by: java.lang.RuntimeException: Unsupported output data type.
at com.sun.media.jai.codecimpl.TIFFImageEncoder.encode(TIFFImageEncoder.java:237)
at com.sun.media.jai.codecimpl.TIFFImageEncoder.encode(TIFFImageEncoder.java:151)
at com.sun.media.jai.opimage.EncodeRIF.create(EncodeRIF.java:70)

When writting my PlanarImage (pi) to disk:

JAI.create("filestore", pi, LocationInDisk );

I have changed TYPE_DOUBLE to TYPE_FLOAT and it works perfectly, but why?

My code is still the same: (all arrays are double-type: subtractThis, multiplyBy, addThis..)

ParameterBlock pbConvert = new ParameterBlock();
pbConvert.addSource(pi);
pbConvert.add(DataBuffer.TYPE_FLOAT);
pi = JAI.create("format", pbConvert, null);

ParameterBlock pbSub = new ParameterBlock();
pbSub.addSource(pi);
pbSub.add(subtractThis);
pi = JAI.create("subtractconst", pbSub, null);

ParameterBlock pbMult = new ParameterBlock();
pbMult.addSource(pi);
pbMult.add(multiplyBy);
pi = JAI.create("multiplyconst", pbMult, null);

ParameterBlock pbSum = new ParameterBlock();
pbSum.addSource(pi);
pbSum.add(addThis);
pi = JAI.create("AddConst", pbSum, null);

System.gc();
sampleModel = pi.getSampleModel();
wr = pi.copyData();

Bob Deen

It's quite possible that the TIFF writer doesn't accept double data.
The ImageIO infrastructure allows for it, but that doesn't mean any
given file format writer implementation actually DOES it. You may have
to switch formats if you really want double, or fix the implementation.
Note that this is just supposition; I don't recall offhand whether it
supports double or not. But it wouldn't surprise me if it didn't.

Another possible factor is that double is a bit of a poor stepchild.
The original DataBuffer et al classes in java.awt.image didn't have
double as a type... which is why there's a DataBufferDouble in JAI.
They added it in java 1.4 but it was never removed from JAI for
backwards-compatibility reasons, and I'm not sure if JAI is using the
new or the old. This can sometimes cause issues.

However, the same situation existed for float (it wasn't supported
either)... so if it works for float, that's probably not it.

-Bob

jai-interest@javadesktop.org wrote:
> Nobody?
>
> I´ve been watching error traces and I found:
>
> Caused by: java.lang.RuntimeException: Unsupported output data type.
> at com.sun.media.jai.codecimpl.TIFFImageEncoder.encode(TIFFImageEncoder.java:237)
> at com.sun.media.jai.codecimpl.TIFFImageEncoder.encode(TIFFImageEncoder.java:151)
> at com.sun.media.jai.opimage.EncodeRIF.create(EncodeRIF.java:70)
>
> When writting my PlanarImage (pi) to disk:
>
> JAI.create("filestore", pi, LocationInDisk );
>
> I have changed TYPE_DOUBLE to TYPE_FLOAT and it works perfectly, but why?
>
> My code is still the same: (all arrays are double-type: subtractThis, multiplyBy, addThis..)
>
> ParameterBlock pbConvert = new ParameterBlock();
> pbConvert.addSource(pi);
> pbConvert.add(DataBuffer.TYPE_FLOAT);
> pi = JAI.create("format", pbConvert, null);
>
> ParameterBlock pbSub = new ParameterBlock();
> pbSub.addSource(pi);
> pbSub.add(subtractThis);
> pi = JAI.create("subtractconst", pbSub, null);
>
> ParameterBlock pbMult = new ParameterBlock();
> pbMult.addSource(pi);
> pbMult.add(multiplyBy);
> pi = JAI.create("multiplyconst", pbMult, null);
>
> ParameterBlock pbSum = new ParameterBlock();
> pbSum.addSource(pi);
> pbSum.add(addThis);
> pi = JAI.create("AddConst", pbSum, null);
>
> System.gc();
> sampleModel = pi.getSampleModel();
> wr = pi.copyData();
> [Message sent by forum member 'sportinguista']
>
> http://forums.java.net/jive/thread.jspa?messageID=477976
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>

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