Skip to main content

Display TiledImages Problem

9 replies [Last post]
j_acon
Offline
Joined: 2005-09-21
Points: 0

Hello again, in need of wisdom again :/

PlanarImage image = new TiledImage(decoder.decodeAsRenderedImage(i), true);
DisplayJAI.set(image);

that code works fine with small images, but when i load a 10meg file it will load with no problem, but it doesn't get displayed at all on the applet. Can anyone tell me what is wrong or what can i do to get it working?

Reply viewing options

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

No, it is brian.burkhalter@sun.com.

> Is this jai-interest@javadesktop.org your email address?

----------------
Brian Burkhalter
Advanced Development/Media & Entertainment
Market Development Engineering
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.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

j_acon
Offline
Joined: 2005-09-21
Points: 0

Email away, thanks a lot Brian

j_acon
Offline
Joined: 2005-09-21
Points: 0

I found the reason for this problem.

Is the way i scaled the images.

int kernelSize = 5;
float[] kernelMatrix = new float[kernelSize*kernelSize];
for(int k=0;k kernelMatrix[k] = 1.0f/(kernelSize*kernelSize);

KernelJAI kernel = new KernelJAI(kernelSize,kernelSize,kernelMatrix);
RenderedImage convolve = JAI.create("convolve", image, kernel);
kernel = null;
image.dispose();
System.gc();

Interpolation interp = Interpolation.getInstance(Interpolation.INTERP_BILINEAR);

ParameterBlock pb_scale = new ParameterBlock();
pb_scale.addSource(convolve);
convolve = null;
System.gc();
//pb_scale.addSource(image);
pb_scale.add(scale); //x
pb_scale.add(scale); //y
pb_scale.add(0.0F); //default
pb_scale.add(0.0F);
pb_scale.add(interp);

PlanarImage newImage = new TiledImage(JAI.create("scale", pb_scale), true);
pb_scale.removeSources();
pb_scale = null;
System.gc();

return newImage;

If i remove the convolve part, the image will appear. But then the downscale looks really bad. What can i do to solve this?

Brian Burkhalter

This might give you some ideas:

http://archives.java.sun.com/cgi-bin/wa?A2=ind0311&L=jai-interest&F=&S=&...

Brian

On Wed, 22 Jun 2005 jai-interest@javadesktop.org wrote:

> If i remove the convolve part, the image will appear. But then the downscale looks really bad. What can i do to solve this?

----------------
Brian Burkhalter
Advanced Development/Media & Entertainment
Market Development Engineering
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.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

j_acon
Offline
Joined: 2005-09-21
Points: 0

Thanks Brian, awesome stuff.

Just got a problem using

FilteredSubsample and SubsampleAverage

At certain scales this 2 classes will return an image, but it never gets draw. Eg at the scale of 0.24 using SubsampleAverage the image doesn't diplay. But at 0.20 and 0.25 it displays.

Same for FilteredSubsample.

Would you know why does it happen?

Brian Burkhalter

I think the information supplied is insufficient to determine a solution. Are
you able to provide a self-contained test case (no editing required, not even
of image file path) which would allow the problem to be reproduced?

Thanks,

Brian

On Fri, 24 Jun 2005 jai-interest@javadesktop.org wrote:

> Thanks Brian, awesome stuff.
>
> Just got a problem using
>
> FilteredSubsample and SubsampleAverage
>
> At certain scales this 2 classes will return an image, but it never gets draw. Eg at the scale of 0.24 using SubsampleAverage the image doesn't diplay. But at 0.20 and 0.25 it displays.
>
> Same for FilteredSubsample.
>
> Would you know why does it happen?
> ---
> [Message sent by forum member 'j_acon' (Jorge)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=94742&#94742
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Advanced Development/Media & Entertainment
Market Development Engineering
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.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

j_acon
Offline
Joined: 2005-09-21
Points: 0

Hello Brian, here is a test version.

Do you have an address where i can mail send you the code and image? i can post the code in here. The image is 10 meg tif file, with only one page.

/*
* TestZoom.java
*
* Created on 27 June 2005, 09:41
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
import com.sun.media.jai.codec.*;
import java.io.*;
import java.awt.*;
import java.awt.print.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.image.renderable.ParameterBlock;
import javax.swing.*;
import javax.swing.border.*;
import java.util.*;
import javax.media.jai.*;
import java.net.*;
import com.sun.media.jai.widget.*;
import javax.media.jai.widget.ScrollingImagePanel;

/**
*
* @author jorgea
*/
public class TestZoom extends javax.swing.JApplet {

private Dimension scrollDimension = new Dimension(1000, 800);
private ImageDecoder decoder;
private int numberOfPages;
private JScrollPane scrollPane;
private DisplayJAI display;

/** Initializes the applet */
public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}

private void initComponents() {
display = new DisplayJAI();
scrollPane = new JScrollPane();
scrollPane.setPreferredSize(scrollDimension);
scrollPane.setViewportView(display);
this.getContentPane().add(scrollPane);
loadFile("http://localhost:80/viewer/SCAN00346075.tif");
PlanarImage image = readPage(0);
//this won't display
//image = scaleImage(image, findScale(image.getWidth(), image.getHeight()));

//this displays
//image = scaleImage(image, 0.5);

//this won't display
image = scaleImage(image, 0.25);

//this won't display
//image = scaleImage(image, 0.02);

//without scaling it will display
display.set(image);

}

public boolean loadFile(String location)
{
try{
URL url = new URL(location);
InputStream is;
is = url.openStream();

SeekableStream s = new MemoryCacheSeekableStream(is);
TIFFDecodeParam param = null;
decoder = ImageCodec.createImageDecoder("tiff", s, param);

numberOfPages = decoder.getNumPages();
return true;
}
catch(Exception e)
{
System.out.println("Error Loading File. Class ImageFileDecoder.loadFile()");
e.printStackTrace();
return false;
}
}

public PlanarImage readPage(int pageNumber)
{
try{
PlanarImage image = new TiledImage(decoder.decodeAsRenderedImage(pageNumber), true);
return image;
}
catch(Exception e)
{
System.out.println("Error Reading Page. Class ImageFileDecoder.readPage()");
e.printStackTrace();
return null;
}
}

public PlanarImage scaleImage(PlanarImage image, double scale)
{
System.out.println(scale);
try
{
RenderingHints hints = new RenderingHints(null);
hints.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
hints.add(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON));
hints.add(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
hints.add(new RenderingHints(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE));

ParameterBlock pb_scale = new ParameterBlock();
pb_scale.addSource(image);
pb_scale.add(scale);
pb_scale.add(scale);
PlanarImage newImage = new TiledImage(JAI.create("SubsampleAverage", pb_scale, hints),true);
image.dispose();
pb_scale.removeSources();
pb_scale = null;
System.gc();
return newImage;
}
catch(Exception e)
{
System.out.println("Scaling Fail");
e.printStackTrace();
return image;
}
}

private double findScale(int width, int height)
{
int newWidth;
int newHeight;
double scale;
if(width >= height)
{
newWidth = scrollDimension.width;
scale = (double)newWidth/(double)width;
}
else
{
newHeight = scrollDimension.height;
scale = (double)newHeight/(double)height;
}
return scale;
}

}

Brian Burkhalter

You may just sent the image to me via e-mail. If that doesn't work I can give
you a URL.

Brian

On Sun, 26 Jun 2005 jai-interest@javadesktop.org wrote:

> Hello Brian, here is a test version.
>
> Do you have an address where i can mail send you the code and image? i can post the code in here. The image is 10 meg tif file, with only one page.
>
> /*
> * TestZoom.java
> *
> * Created on 27 June 2005, 09:41
> *
> * To change this template, choose Tools | Options and locate the template under
> * the Source Creation and Management node. Right-click the template and choose
> * Open. You can then make changes to the template in the Source Editor.
> */
> import com.sun.media.jai.codec.*;
> import java.io.*;
> import java.awt.*;
> import java.awt.print.*;
> import java.awt.event.*;
> import java.awt.image.*;
> import java.awt.image.renderable.ParameterBlock;
> import javax.swing.*;
> import javax.swing.border.*;
> import java.util.*;
> import javax.media.jai.*;
> import java.net.*;
> import com.sun.media.jai.widget.*;
> import javax.media.jai.widget.ScrollingImagePanel;
>
> /**
> *
> * @author jorgea
> */
> public class TestZoom extends javax.swing.JApplet {
>
> private Dimension scrollDimension = new Dimension(1000, 800);
> private ImageDecoder decoder;
> private int numberOfPages;
> private JScrollPane scrollPane;
> private DisplayJAI display;
>
> /** Initializes the applet */
> public void init() {
> try {
> java.awt.EventQueue.invokeAndWait(new Runnable() {
> public void run() {
> initComponents();
> }
> });
> } catch (Exception ex) {
> ex.printStackTrace();
> }
> }
>
> private void initComponents() {
> display = new DisplayJAI();
> scrollPane = new JScrollPane();
> scrollPane.setPreferredSize(scrollDimension);
> scrollPane.setViewportView(display);
> this.getContentPane().add(scrollPane);
> loadFile("http://localhost:80/viewer/SCAN00346075.tif");
> PlanarImage image = readPage(0);
> //this won't display
> //image = scaleImage(image, findScale(image.getWidth(), image.getHeight()));
>
> //this displays
> //image = scaleImage(image, 0.5);
>
> //this won't display
> image = scaleImage(image, 0.25);
>
> //this won't display
> //image = scaleImage(image, 0.02);
>
> //without scaling it will display
> display.set(image);
>
>
>
>
> }
>
> public boolean loadFile(String location)
> {
> try{
> URL url = new URL(location);
> InputStream is;
> is = url.openStream();
>
> SeekableStream s = new MemoryCacheSeekableStream(is);
> TIFFDecodeParam param = null;
> decoder = ImageCodec.createImageDecoder("tiff", s, param);
>
> numberOfPages = decoder.getNumPages();
> return true;
> }
> catch(Exception e)
> {
> System.out.println("Error Loading File. Class ImageFileDecoder.loadFile()");
> e.printStackTrace();
> return false;
> }
> }
>
> public PlanarImage readPage(int pageNumber)
> {
> try{
> PlanarImage image = new TiledImage(decoder.decodeAsRenderedImage(pageNumber), true);
> return image;
> }
> catch(Exception e)
> {
> System.out.println("Error Reading Page. Class ImageFileDecoder.readPage()");
> e.printStackTrace();
> return null;
> }
> }
>
> public PlanarImage scaleImage(PlanarImage image, double scale)
> {
> System.out.println(scale);
> try
> {
> RenderingHints hints = new RenderingHints(null);
> hints.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
> hints.add(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON));
> hints.add(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
> hints.add(new RenderingHints(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE));
>
> ParameterBlock pb_scale = new ParameterBlock();
> pb_scale.addSource(image);
> pb_scale.add(scale);
> pb_scale.add(scale);
> PlanarImage newImage = new TiledImage(JAI.create("SubsampleAverage", pb_scale, hints),true);
> image.dispose();
> pb_scale.removeSources();
> pb_scale = null;
> System.gc();
> return newImage;
> }
> catch(Exception e)
> {
> System.out.println("Scaling Fail");
> e.printStackTrace();
> return image;
> }
> }
>
> private double findScale(int width, int height)
> {
> int newWidth;
> int newHeight;
> double scale;
> if(width >= height)
> {
> newWidth = scrollDimension.width;
> scale = (double)newWidth/(double)width;
> }
> else
> {
> newHeight = scrollDimension.height;
> scale = (double)newHeight/(double)height;
> }
> return scale;
> }
>
>
> }
> ---
> [Message sent by forum member 'j_acon' (Jorge)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=95330&#95330
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Advanced Development/Media & Entertainment
Market Development Engineering
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.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

j_acon
Offline
Joined: 2005-09-21
Points: 0

Is this jai-interest@javadesktop.org your email address?