Image resolution algorithm

Hello!

I "reload" a request (first posted on the Java 2D Forum) hoping for more success, this time:

Please, somebody help me, if possible, with an algorithm (or a pointer to such an algorithm) that allows saving an image in a file, with a pre-set resolution (pixels per inch), to have the possibility to visualize (process) a set of patterns (shapes) having the same dimensions in inches (millimeters), which can be represented using different numbers of pixels - like scanning the same image at different dpi resolutions.

Best regards,

Sandu Crasteti

[582 byte] By [ssaanna] at [2007-10-2 12:56:00]
# 1

Sorry if I misunderstood, but if you have files with a preset pixels-per-inch resolution, and a preset size, then they will always have the same amount of pixels.

Also, try being more specific about which part you're having trouble with. Is it the saving part? The scanning? One of the parts in between?

DaanSa at 2007-7-13 10:11:50 > top of Java-index,Other Topics,Algorithms...
# 2

Thank you for your interest!

The problem is to start with an image Img1 characterized by a resolution r1 (pixels per inch - ppi), a width (in pixels) w1p, a width (in inches) w1i, a height (in pixels) h1p, and a height (in inches) h1i, and save it as an image Img2, characterized by the resolution r2, the widths w2p and w2i, and the heights h2p and h2i, so that w2p = w1p and h2p = h1p, but with w2i different than w1i, and h2i different than h1i.

But when making such a transform, an algorithm should be applied (like - but not identically - in the case of magnifying or resizing an image, which consists after all in a matrix of pixels) so that the result should be the same as in the case of using a scanner with the resolution of r2 dots per inch (dpi) to obtain the file Img2.

ssaanna at 2007-7-13 10:11:50 > top of Java-index,Other Topics,Algorithms...
# 3

I'm still not sure if I understand correctly:

Your first paragraph gives me the impression that you want to have an img2 with the same pixel data as img1, but a different pixels-per-inch resolution.

Your second paragraph however, confuses me. As far as I understand things, two scanners with two different resolutions would provide two images with the same size in inches, but different resolutions. E.g., Scanner highRes would create an image of 100 x 100 pixels @ 10 dpi (= 10 x 10 inches) while Scanner lowRes would create an image of 50 x 50 pixels @ 5 dpi (= 10 x 10 inches)

DaanSa at 2007-7-13 10:11:50 > top of Java-index,Other Topics,Algorithms...
# 4
@OP: Do you mean something like this:Say you have the following black/white picture:0 0 0 00 0 1 00 1 1 00 0 0 0and zooming in on the middle would produce the following picture:0 0 1 10 0 1 11 1 1 11 1 1 1?
prometheuzza at 2007-7-13 10:11:50 > top of Java-index,Other Topics,Algorithms...
# 5

I don't have an algorithm for you, but I can tell you how it is that people think about this problem.

What you are doing is resampling an image (Google is your friend)

The way that you think about it is this. The original scene from which you created your first image is a perfect two dimemsional function. Associated with any x,y coordinate (and those are real values, not integers) there is a color.

Your first image was just a sampling of that perfect function. You simply wrote down and remembered the values of the perfect function at some integer coordinates and LOST all the rest of the information about that fucntion.

Resampling at a different collections of points would be easy if you had that original function, you would just reevaluate the function at the new set of points. Furthermore, resizing, scaling and skewing is similarly easy, you just apply a transform to the coordinates before you go pluck the value out of the function.

So to solve your problem what you do is recreate the original function (or rather you pretend to recreate the original function. You lost information when you first sampled it and that information is now lost for good). The qestion that you are faced with is how to do that reconstruction.

Basically when you are trying to evaluate the perfect function at a new point (x,y) where that point landed between sample point on the first image x(i) < x < x(i+1) and y(j) < y < y(i) you will want to create a new color that is some blend of the neighboring sample points ( those would be x(i)y(j)x(i+1)y(j) x(i)y(j+1) and x(i+1)y(j+1) and if you want to get fancy you could even include more of the neighbors in the calculation)

All the differrnt ways of doing resampling basically boil down into how fancy a calculation you want to do in the blending. These are all different ways of reconstructing the perfect function that you imagined that you started with.

The simplest blending function that you can use is to do no blending at all, i.e. colro(x,y) = color(x(i),y(j) This method may be good enough for your application.

The reason that people have developed different methods of blending is because no matter what you do you can NOT reconstruct the function perfectly and thus any blending function that you use is introducing artifacts into your supposed reconstruction. For example, the simplest blend that I just mentioned, the NO blending, is pretending that the original function did not smoothly transition from one color to the next, rather is was made up of squares of absolutely uniform color that just happened to be the size of the pixels that you originally scanned at. So if at x(i) is was blue, it remained that exact shade of blue for every x value right up to x(i+1) when it suddenly discontinuously changed to some other color.

So the quick and dirty way to do this image processing is to write your routines that will convert an xy coordinate in your new image system into the nearest coordinates in the old system. (This step has nothing what so ever to do with the blending function that you choose) and then call your blending function. You can then play with blends as much as you like.

Enjoy

marlin314a at 2007-7-13 10:11:50 > top of Java-index,Other Topics,Algorithms...
# 6
1. For DaanS: yes!2. For prometheuzz: no!3. For marlin314: thank you!Best regards!
ssaanna at 2007-7-13 10:11:50 > top of Java-index,Other Topics,Algorithms...