Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JAI interpolation 1

Status
Not open for further replies.

russland

Programmer
Jan 9, 2003
315
CH
hi,
I'm using the function below to resize an image. Unfortunately the thumbnail looks always very "pixel-ish" not matter what Interplocation I choose. Not smooth at all. Any clue?


public RenderedOp resize(PlanarImage planImg, float resizeFactor){
ParameterBlock pb = new ParameterBlock();
pb = new ParameterBlock();
pb.addSource(planImg);
pb.add(resizeFactor);
pb.add(resizeFactor);
pb.add(0.0f);
pb.add(0.0f);
pb.add(new InterpolationNearest());
RenderedOp img = JAI.create("scale", pb, null);

return img;
}
 
Hi,

I used JAI for a batch resizer (all pics to same format...) and was always astonished about the high quality - so I don't really know about JAI problems. But since I have to do pic optimization for websites I made the experience that it strongly depends on the structure of the material (high contrast areas/borders, certain color pairs) and mostly on what had happened to the picture right before.

Since JPG (blocked pixels!) as well as pixel interpolations (mainly by resizing) tend to show pixely areas try to
- avoid making a detailed pic very small or much bigger
- avoid making a pic bigger/smaller and then resize the same pic again
- avoid processing simple graphics with few colors and straight (thin) lines

If you generate the graphics yourself it will be better to recreate them at a different size than to resize them...

Maybe you did not expect this advice (no "programming" solution...) but I believe you have to watch out for these "process parameters" as well, since by doing things in the wrong order I was able to turn an acceptable photograph into something you just hand over to the big archive with the round bucket symbol.

have fun with the JAI API - I think it's great...
Andy
 
thanks, but what's the best softening algorithm for it. Still too pixel-ish.

I'm using the blur method first. The returned RenderedOp I pass to the 2nd function (resize).

cheers


=========================================
public static RenderedOp blur (RenderedOp img){
float softenFactor = 1f;
float blurmatrix[] = {softenFactor/16f, softenFactor/8f, softenFactor/16f, softenFactor/8f, softenFactor/4f, softenFactor/8f, softenFactor/16f, softenFactor/8f, softenFactor/16f};
KernelJAI blurKernel = new KernelJAI (3, 3, blurmatrix);

return JAI.create("convolve", img, blurKernel);
}

=========================================
public RenderedOp resize(PlanarImage planImg, float resizeFactor){
ParameterBlock pb = new ParameterBlock();
pb = new ParameterBlock();
pb.addSource(planImg);
pb.add(resizeFactor);
pb.add(resizeFactor);
pb.add(0.0f);
pb.add(0.0f);
pb.add(new InterpolationBicubic(5));
RenderedOp img = JAI.create("scale", pb, null);

return img;
}
 
alright. This works very nice. I think this operator is not atomic and uses other operators in conjunction. However, works veeeery nice.

Double scalingFactorDouble = new Double(scalingFactor);
ParameterBlock pb = new ParameterBlock();
pb.addSource(image);
pb.add(scalingFactorDouble);
pb.add(scalingFactorDouble);
scaledImage = JAI.create("SubsampleAverage", pb);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top