Skip to main content

Dilation

12 replies [Last post]
hvn
Offline
Joined: 2006-09-19

Hi,

I'm trying to perform dilation on a jpg-picture. As far as I understand I first have to use ColorConvert and Binarize before I can use Dilate. Problem is that I get this message:

operation "ColorConvert" requires 1 source object(s)

but I don't completely understand what I'm doing wrong.
This is part of the source I have so far:

ParameterBlock pb = new ParameterBlock();
pb.addSource(pi_src);
// Maak een gray-scale (single-banded) image
try
{
pi_sb = JAI.create("colorconvert", pb, kernel);
}
catch (IllegalArgumentException iae)
{
System.out.println("pi_sb = " + pi_sb);
iae.printStackTrace();
}
// Maak een binary image
try
{
pi_bin = JAI.create("binarize", pi_sb, kernel);
}
catch (IllegalArgumentException iae)
{
System.out.println("pi_bin = " + pi_bin);
iae.printStackTrace();
}
// Voer dilatie uit
try
{
pi_best = JAI.create("dilate", pi_bin, kernel);
}
catch (IllegalArgumentException iae)
{
iae.printStackTrace();
}

Is this code, apart from the error, ok to do a successfull dilation on a jpg? Help is appreciated.

Thank you.

Reply viewing options

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

You do not need to convert it to grayscale. If it is multi-banded each band
will be processed as a separate grayscale image. Please see

http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/ja...

for more information.

As for converting RGB to color, please see for example

http://archives.java.sun.com/cgi-bin/wa?A2=ind0107&L=jai-interest&P=R519...

On Mon, 12 Dec 2005, jai-interest@javadesktop.org wrote:

> Thank you, but the original image is a colour jpg. So, what is the best way to have it converted to grayscale? As far as I know, only then I can use binarize and dilation or erosion.

----------------
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.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

hvn
Offline
Joined: 2006-09-19

Does this mean the "dilate" operation converts a (colour)jpg image by itself and then performs dilation, in which case neither colorconvert nor binarize are necessary?

Brian Burkhalter

Firstly, once an image is loaded into a RenderedImage it doesn't matter what
format source it was ingested from, e.g., that it came from a JFIF as opposed
to a TIFF file is irrelevant.

As for dilation on color or any other image which has more than one sample per
pixel is that each band is processed independently. In pseudocode for example

for(int b = 0; b < samplesPerPixel; b++) {
destinationBands[b] = dilation(sourceBands[b]);
}

In other words, dilation on a multi-image is defined to be the same as
extracting each band in order using BandSelect, applying Dilate to each band,
and using BandMerge to create the result from the individual band outptus of
Dilate.

Brian

On Wed, 14 Dec 2005, jai-interest@javadesktop.org wrote:

> Does this mean the "dilate" operation converts a (colour)jpg image by itself and then performs dilation, in which case neither colorconvert nor binarize are necessary?

----------------
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.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

hvn
Offline
Joined: 2006-09-19

I'm compiling this:

try
{
System.out.println("image_keuze =" + image_keuze);
pi_src = JAI.create("fileload", image_keuze);
System.out.println("pi_src = " + pi_src);
}
catch (IllegalArgumentException iae)
{
JOptionPane.showMessageDialog(this, "Bestandsfout");
iae.printStackTrace();
}

System.out.println((pi_src == null));
double[][] matrix = {{ 0.3D, 0.59D, 0.11D, 0D }};
ParameterBlock pb = new ParameterBlock();
pb.addSource(pi_src);
pb.add(matrix);
// Maak een gray-scale (single-banded) image
try
{
pi_sb = JAI.create("bandcombine", pb, null);
}
catch (IllegalArgumentException iae)
{
System.out.println("pi_sb = " + pi_sb);
iae.printStackTrace();
}
// Maak een binary image
try
{
pi_bin = JAI.create("binarize", pi_sb, null);
}
catch (IllegalArgumentException iae)
{
System.out.println("pi_bin = " + pi_bin);
iae.printStackTrace();
}
// Voer dilatie uit
try
{
pi_best = JAI.create("dilate", pi_bin, null);
}
catch (IllegalArgumentException iae)
{
iae.printStackTrace();
}

It compiles ok, but when running the program I get these messages:

image_keuze =/mnt/Durbanadmin/Digitale foto's/Test.JPG
pi_src = PlanarImage[minX=0 minY=0 width=0 height=0 tileGridXOffset=0 tileGridYOffset=0 tileWidth=0 tileHeight=0 sampleModel=null colorModel=null]

false

pi_bin = null

java.lang.IllegalArgumentException: operation "Binarize" requires 1 parameter object(s).

Is my way of using the operations wrong? What do I miss?

Brian Burkhalter

You're not supplying the threshold parameter Binarize as it says. Please refer
to the javax.media.jai.operator package

http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/ja...

for a description of all intrinsic JAI operations.

Brian

On Thu, 15 Dec 2005, jai-interest@javadesktop.org wrote:

> It compiles ok, but when running the program I get these messages:
>
> image_keuze =/mnt/Durbanadmin/Digitale foto's/Test.JPG
> pi_src = PlanarImage[minX=0 minY=0 width=0 height=0 tileGridXOffset=0 tileGridYOffset=0 tileWidth=0 tileHeight=0 sampleModel=null colorModel=null]
>
> false
>
> pi_bin = null
>
> java.lang.IllegalArgumentException: operation "Binarize" requires 1 parameter object(s).
>
>
>
> Is my way of using the operations wrong? What do I miss?

----------------
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.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

hvn
Offline
Joined: 2006-09-19

OK, that was obvious. But when I look for "Binarize" I get 2 different possibilities:
http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/in... shows

public static RenderedOp create(RenderedImage source0,
Double threshold,
RenderingHints hints)

with threshold as 2nd argument,
and

http://java.sun.com/products/java-media/jai/forDevelopers/samples/Binari...
shows

// Binarize the image.
PlanarImage dst =
JAI.create("binarize", src, new Double(threshold[0]));

with threshold as 3rd argument? Which one should I take?

Brian Burkhalter

These methods are on different classes, right? The former on
BinarizeDescriptor and the latter on JAI.

Brian

On Thu, 15 Dec 2005, jai-interest@javadesktop.org wrote:

> OK, that was obvious. But when I look for "Binarize" I get 2 different possibilities:
> http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/in... shows
>
> public static RenderedOp create(RenderedImage source0,
> Double threshold,
> RenderingHints hints)
>
> with threshold as 2nd argument,
> and
>
> http://java.sun.com/products/java-media/jai/forDevelopers/samples/Binari...
> shows
>
> // Binarize the image.
> PlanarImage dst =
> JAI.create("binarize", src, new Double(threshold[0]));
>
> with threshold as 3rd argument? Which one should I take?
> ---
> [Message sent by forum member 'hvn' (H van Niekerk)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=130748&#130748
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.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.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

hvn
Offline
Joined: 2006-09-19

Since I've used the JAI throughout the rest of the methods, I took the latter. Using the example from the link, I thought it'd work this time. Unfortunately, I got exactly the same errormessage as before. So my question is: if I want to perform dilation on a colour jpg file, is using the JAI class with the operations fileload, (making histogram/getting threshold), binarize and dilate enough to do the job? When I use existing visionsoftware, these are the operations for getting the job done. So what am I doing wrong here?

rafael.santos@lac.inpe.br

Hello,

> I'm trying to perform dilation on a jpg-picture. As far as I understand I
> first have to use ColorConvert and Binarize before I can use Dilate. Problem
> is that I get this message:

You don't really need to ColorConvert it -- probably you mean convert the image
to grayscale (there are several methods).

There is a dilate/erode example in
http://www.lac.inpe.br/~rafael.santos/Java/JAI/operators.html, where you can
find several other operators examples.

hope it helps
Rafael

-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/

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

rafael.santos@lac.inpe.br

Hello,

> I'm trying to perform dilation on a jpg-picture. As far as I understand I
> first have to use ColorConvert and Binarize before I can use Dilate. Problem
> is that I get this message:

You don't really need to ColorConvert it -- probably you mean convert the image
to grayscale (there are several methods).

There is a dilate/erode example in
http://www.lac.inpe.br/~rafael.santos/Java/JAI/operators.html, where you can
find several other operators examples.

hope it helps
Rafael

-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/

hvn
Offline
Joined: 2006-09-19

Thank you, but the original image is a colour jpg. So, what is the best way to have it converted to grayscale? As far as I know, only then I can use binarize and dilation or erosion.

Rafael Santos

Hello,

>Thank you, but the original image is a colour jpg. So, what is the best way to have it converted to grayscale? As far as I know, only then I can use binarize and dilation or erosion.
>
>
There are some hints on the FAQ:
http://java.sun.com/products/java-media/jai/forDevelopers/jaifaq.html#1bit
This may also be used:

double[][] matrix = {{ 0.3D, 0.59D, 0.11D, 0D }};
ParameterBlock pb = new ParameterBlock();
pb.addSource(input);
pb.add(matrix);
output = JAI.create("BandCombine", pb, null);

Rafael

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