Scaling big b/w images --> poor display quality

Hi everyone !!

I'm displaying big images with Java 2D (PNG 5000 x 5000 pixels) and downscale the images by using Graphics.drawImage(x, y, width, height,...).

The problem is that the scaled images are drawn in low quality. Setting RenderHints doesn't help because the images are only black and white, so that interpolation doesn't help much...

The images are black and white CAD outputs (lines, etc.) and scaling them to lower size leads to the loss of pixels details....

Is there any way to improve the display quality of such scaled b/w images ?

[587 byte] By [Pepilein] at [2007-9-26 3:07:40]
# 1

keep in mind i'm going off of memory here, so some of these methods and static instances may be misnamed...

you can get a scaled instance that is rescaled with a different (better) algorithm for downscaling... if you do myImage.getScaledInstance(<specify how to scale here>, Image.SCALE_SMOOTH); then it returns an image that i BELIEVE has been put through a blur filter and then resized... either way it works really well with color images, and I assume the same with black and white... actually come to think of it, it will give gray pixels, not just black and white, so if you need only black and white pixels displayed this might not be what you need

does that help?

kentyman23 at 2007-6-29 11:11:38 > top of Java-index,Security,Cryptography...
# 2

From having worked with images a little biet when I had a job in a sign shop, I suspect that your problem isn't one of finding the right routine for scaling the pixel image. One of our biggest headaches in making signs with a Computer Aided Signmaking system (similar to CAD) was dealing with the transition between pixel formats and vector formats.

Once the image is in pixels, the game is up unless you custom write your own scaling routine that esentially recognizes shapes, converts them to vector objects, and then re-draws them at lower resolution. I am sure that that is likely to be a virtual imposibility, though you could probably sell such code for big bucks if it worked. :).

What you really need to do is get the vector format file (eg. *.DXF ), not the high-res bitmap, and draw a new bitmap. Otherwise there is almost no way for the scaling routine to know which pixels are important. The basic problem is your program doesn't understand the drawing, and therefore can't make intelligent decisions about what it needs to keep and what is unimportant.

However, as I write this, I realize that since you are talking about black and white only, you might be able to write (or find) a routine that picked a background (black or white) and always wrote forground if any pixel contributing to the new pixel was forground, thus retaining thin lines. (probably introducing some level of distortion each time it scaled though).

Me, I'd just get the vector format, and redraw things if possible :)

Hope this helps,

Gus

Sinprejic at 2007-6-29 11:11:38 > top of Java-index,Security,Cryptography...
# 3
hi,i'm resizing a part of the image.tell me what do u do if u want to draw the image zooming from the center.how do u calculate the x,y coordinated yo be given in drawimage.thankssangeeta
sangeeta_bg at 2007-6-29 11:11:38 > top of Java-index,Security,Cryptography...
# 4

For those of you struggling with this problem, I think kentyman23's solution is the correct one. I had the same problems described (poor image quality after scaling) when displaying scanned documents (JPG's) in a JPanel. Using the Image.getScaledInstance() method with the Image.SCALE_SMOOTH parameter as he describes greatly improves the clarity of my documents when I then draw the resulting image in the JPanel.

There is a downside however: I've seen a fairly significant degradation in rendering performance (i.e., it takes a lot longer to draw an image that has been scaled with SCALE_SMOOTH). I suspect this would be improved with better hardware, although I don't have the slowest hardware by any means: PIII 650Mhz, 64MB NVIDIA GeForce2 AGP4x. I've also noticed some "banding" in the image when using the SCALE_SMOOTH parameter, which seems to happen intermittently.

Anyone know if there is a fix for this performance hit (other than faster hardware)? Also, any solution for the "banding" problem?

stevemiles at 2007-6-29 11:11:38 > top of Java-index,Security,Cryptography...