Skip to main content

Deinterlace the image in JAI

17 replies [Last post]
cohodetector
Offline
Joined: 2007-07-12
Points: 0

Hello,
Is there an easier way to deinterlace an image in JAI? I mean is there a class that does the deinterlace in JAI?

Reply viewing options

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

I missed this. Duh. That should work.

Brian

On Thu, 12 Jul 2007, Bob Deen wrote:

> Is this really challenging?
>
> How about simply using Scale, with no interpolation (nearest neighbor) with a
> Y factor of 0.5 and an X factor of 1.0? That should accomplish the task
> simply and easily, should it not?
>
> As for even vs. odd lines, if Scale doesn't have an offset parameter (I don't
> recall), then just use Translate to move everything up (or down?) one line
> and then do the Scale.

----------------
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

James Cheng

> On Thu, 12 Jul 2007, Bob Deen wrote:
>
>> Is this really challenging?
>>
>> How about simply using Scale, with no interpolation (nearest neighbor)
>> with a Y factor of 0.5 and an X factor of 1.0? That should accomplish
>> the task simply and easily, should it not?
>>
>> As for even vs. odd lines, if Scale doesn't have an offset parameter
>> (I don't recall), then just use Translate to move everything up (or
>> down?) one line and then do the Scale.

This should be fast, but probably doesn't have the best quality.

Interestingly enough, this is similar to "line doubling", a.k.a.
"bob deinterlacing", as mentioned on this page:

http://en.wikipedia.org/wiki/Deinterlacing

-James

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

Bob Deen

> well, first my program streams the video from the remote area, and
> then i took a snapshot image of those streaming video for an image
> analysis. I took a snapshot to make it a still image, so it is
> easier to analyze. The snapshot returns a PlanarImage; however, the
> images from the video are interlaced. Hence, i have to deinterlace
> that PlanarImage. Deinterlacing means separating even and odd lines
> of that PlanarImage. I did the deinterlace manually; however, i am
> stuck at converting those deinterlace images to a RenderedImage
> format. I need those deinterlace images in the RenderedImage format
> because i am performing the ImagePyramid operation after the
> deinterlace, and ImagePyramid only takes RenderedImage. So, i was
> wondering is there a class in JAI that does the deinterlacing of an
> image and return a RenderedImage. Here is my manual deinterlace
> code so far:

Is this really challenging?

How about simply using Scale, with no interpolation (nearest
neighbor) with a Y factor of 0.5 and an X factor of 1.0? That should
accomplish the task simply and easily, should it not?

As for even vs. odd lines, if Scale doesn't have an offset parameter
(I don't recall), then just use Translate to move everything up (or
down?) one line and then do the Scale.

-Bob

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

cohodetector
Offline
Joined: 2007-07-12
Points: 0

Wow, thanks for all the helps. I have one more question. Can i create a gray-scale RenderedImage from an int array? the int array contains the integer values between 0 and 255. Here is the code:

public RenderedImage convertBufferToPlanarImage(int[][] srcImg, int srcWidth, int srcHeight)
{
DataBufferInt dBuffer = new DataBufferInt(srcImg, srcWidth * srcHeight);
SampleModel imgSampleModel = RasterFactory.createBandedSampleModel(DataBuffer.TYPE_INT, srcWidth, srcHeight, 1);
ColorModel imgColorModel = PlanarImage.createColorModel(imgSampleModel);
WritableRaster imgWritableRaster = RasterFactory.createWritableRaster(imgSampleModel, dBuffer, new Point(0,0));
BufferedImage srcBufferedImg = new BufferedImage(imgColorModel, imgWritableRaster, false, null);

ParameterBlock pb = new ParameterBlock();
pb.add(srcBufferedImg);
return (RenderedImage) JAI.create("AWTImage",pb);
}

Message was edited by: cohodetector

Brian Burkhalter

A BufferedImage is already a RenderedImage so why would you need to convert?

On Fri, 13 Jul 2007, jai-interest@javadesktop.org wrote:

> Wow, thanks for all the helps. I have one more question. Can i create a gray-scale RenderedImage from an int array? the int array contains the integer values between 0 and 255. Here is the code:
>
> public RenderedImage convertBufferToPlanarImage(int[][] srcImg, int srcWidth, int srcHeight)
> {
> DataBufferInt dBuffer = new DataBufferInt(srcImg, srcWidth * srcHeight);
> SampleModel imgSampleModel = RasterFactory.createBandedSampleModel(DataBuffer.TYPE_INT, srcWidth, srcHeight, 1);
> ColorModel imgColorModel = PlanarImage.createColorModel(imgSampleModel);
> WritableRaster imgWritableRaster = RasterFactory.createWritableRaster(imgSampleModel, dBuffer, new Point(0,0)); //note new Point(0,0) can be replace with null.
> BufferedImage srcBufferedImg = new BufferedImage(imgColorModel, imgWritableRaster, false, null);
>
> ParameterBlock pb = new ParameterBlock();
> pb.add(srcBufferedImg);
> return (RenderedImage) JAI.create("AWTImage",pb);
> }

----------------
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

cohodetector
Offline
Joined: 2007-07-12
Points: 0

Oh, i thought i need to convert to RenderedImage so that i can perform ImagePyramid. Do i need not to convert to RenderedImage. This is how i implement my ImagePyramid:

public RenderedImage GetImagePyramid(RenderedImage originalImage, int imageLevel, float scaleFactor)
{
RenderedOp downSampler;
RenderedImage temp;
ImageMIPMap pyramid;
PlanarImage tempPlanarImage;

downSampler = createScaleOp(originalImage, scaleFactor);
downSampler.removeSources(); //This line is needed for getting the image pyramid otherwise only return one level below.
downSampler = createScaleOp(downSampler, scaleFactor);

pyramid = new ImageMIPMap(originalImage,downSampler);
if(imageLevel == 1)
{
temp = pyramid.getCurrentImage();
}
else
{
temp = pyramid.getImage(imageLevel);
}
return temp;
}

Brian Burkhalter

The JAI operations in rendered mode accept RenderedImages in general of which
PlanarImage and BufferedImage are two examples. Generally if the source is a
non-PlanarImage RenderedImage then it gets wrapped automatically.

On Fri, 13 Jul 2007, jai-interest@javadesktop.org wrote:

> Oh, i thought i need to convert to RenderedImage so that i can perform ImagePyramid. Do i need not to convert to RenderedImage. This is how i implement my ImagePyramid:
>
> public RenderedImage GetImagePyramid(RenderedImage originalImage, int imageLevel, float scaleFactor)
> {
> RenderedOp downSampler;
> RenderedImage temp;
> ImageMIPMap pyramid;
> PlanarImage tempPlanarImage;
>
>
> downSampler = createScaleOp(originalImage, scaleFactor);
> downSampler.removeSources(); //This line is needed for getting the image pyramid otherwise only return one level below.
> downSampler = createScaleOp(downSampler, scaleFactor);
>
> pyramid = new ImageMIPMap(originalImage,downSampler);
> if(imageLevel == 1)
> {
> temp = pyramid.getCurrentImage();
> }
> else
> {
> temp = pyramid.getImage(imageLevel);
> }
> return temp;
> }

----------------
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

cohodetector
Offline
Joined: 2007-07-12
Points: 0

ok. i see. i don't really need to convert to RenderedImage.

thanks

cohodetector

Brian Burkhalter

Could you please be a little more specific?

On Thu, 12 Jul 2007, jai-interest@javadesktop.org wrote:

> Is there an easier way to deinterlace an image in JAI? I mean is there a class that does the deinterlace in JAI?

----------------
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

cohodetector
Offline
Joined: 2007-07-12
Points: 0

well, first my program streams the video from the remote area, and then i took a snapshot image of those streaming video for an image analysis. I took a snapshot to make it a still image, so it is easier to analyze. The snapshot returns a PlanarImage; however, the images from the video are interlaced. Hence, i have to deinterlace that PlanarImage. Deinterlacing means separating even and odd lines of that PlanarImage. I did the deinterlace manually; however, i am stuck at converting those deinterlace images to a RenderedImage format. I need those deinterlace images in the RenderedImage format because i am performing the ImagePyramid operation after the deinterlace, and ImagePyramid only takes RenderedImage. So, i was wondering is there a class in JAI that does the deinterlacing of an image and return a RenderedImage. Here is my manual deinterlace code so far:

//Deinterlace.java
//June 15, 2007
//Version 2.0
//Deinterlace an image fromt the video. The images are intelace; hence, we have to deinterlace for image analysis.

import javax.media.jai.*; //java advanced imaging package

public class Deinterlace{
RenderedImage oddRenderedImage;
RenderedImage evenRenderedImage;

public void DeinterlaceImage(PlanarImage img)
{
int width = img.getWidth();
int height = img.getHeight();
int actualHeight = 0;
int deinterlaceHeight = (int) height / 2;

int [][] oddImage = new int[width][deinterlaceHeight];
int [][] evenImage = new int[width][deinterlaceHeight];

//This loop deinterlace a PlanarImage by separating even and odd lines from //PlanarImage.
for (int h = 0; h < height; h++)
{
for (int w = 0; w < width; w++)
{

Message was edited by: cohodetector

cohodetector
Offline
Joined: 2007-07-12
Points: 0

oddImage[w][actualHeight]=img.getData().getSample(w,h,0);//separate oddlines
evenImage[w][actualHeight]= img.getData().getSample(w,h,0);//separate evenlines

}
actualHeight++;
h++; //increment the original image height becuase of deinterlacing.

}
/////////////////////////////////////////////////////////////////////////////////////////////
// I need some code in here that convert the oddImage and //
// evenImage array to a RenderedImage. //
//////////////////////////////////////////////////////////////////////////////////////////////

}

public RenderedImage getOddImage()
{
return oddRenderedImage;
}
public RenderedImage getEvenImage()
{
return evenRenderedImage;
}
}

sorry, it got cut off. I guess there is a limit on the post message size

Message was edited by: cohodetector

Brian Burkhalter

Perhaps in the Forum interface but not if you use the mailing list (they are
cross-posted).

On Thu, 12 Jul 2007, jai-interest@javadesktop.org wrote:

> sorry, it got cut off. I guess there is a limit on the post message size

----------------
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

cohodetector
Offline
Joined: 2007-07-12
Points: 0

ok. I looked the entire JAI classes and Deinterlace class does not exist in the JAI. Hence, i have to write the code myself. The last question that i have is that how do i convert the two dimension array int[][] to a RenderedImage? The int[][] array contains the grayscale values between 0 and 255.

Thanks

cohodetector

Brian Burkhalter

You are correct. I would suggest writing it as an operator.

I really suggest reading this background material first

http://java.sun.com/javase/6/docs/technotes/guides/2d/spec/j2d-image.htm...

and re-posting if you have trouble.

In summary you will need to create one or more Rasters depending on whether
the image is tiled (probably not). Each Raster contains a SampleModel and a
DataBuffer. The DataBuffer contains the actual data array the layout of which
is described by the SampleModel.

The image contains one Raster per tile and also a single ColorModel which
itself contains a ColorSpace.

On Thu, 12 Jul 2007, jai-interest@javadesktop.org wrote:

> ok. I looked the entire JAI classes and Deinterlace class does not exist in the JAI. Hence, i have to write the code myself. The last question that i have is that how do i convert the two dimension array int[][] to a RenderedImage? The int[][] array contains the grayscale values between 0 and 255.

----------------
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

cohodetector
Offline
Joined: 2007-07-12
Points: 0

cool. That's very helpful. I appreciated it Brian. I will post more question if i need help. Also, one last question. How do i get to the mailing list so that i can post longer message?

Thanks

cohodetector

Brian Burkhalter

You would need to join the JAI project

https://jai.dev.java.net/

and subscribe to the "interest" mailing list

https://jai.dev.java.net/servlets/SummarizeList?listName=interest

On Thu, 12 Jul 2007, jai-interest@javadesktop.org wrote:

> cool. That's very helpful. I appreciated it Brian. I will post more question if i need help. Also, one last question. How do i get to the mailing list so that i can post longer message?
>
> Thanks
>
> cohodetector
> [Message sent by forum member 'cohodetector' (cohodetector)]
>
> http://forums.java.net/jive/thread.jspa?messageID=226444
>
> ---------------------------------------------------------------------
> 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

Fork Labs

Hello cohodetector,

You could also take a look at class RasterAdapter from my project
jai-operators, it helps make image from arrays of different types :

https://jai-operators.dev.java.net/

Regards,

Daniel Léonard

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