number of neighbors

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Post Reply
robuntu
Posts: 41
Joined: 2012-01-22T10:56:10-07:00
Authentication code: 8675308

number of neighbors

Post by robuntu »

Hi,
this is a theoretical question wich affects my practical problem.
I have to enlarge a given image to a huge size and then cut it
into slices. It is simular to creating photo-wallpapers.
The slices will be 200 inches long (from Top to bottom)
and 20 inches wide, but up to 100 of them.
You can imagine the large size of the toal amount of pixels.

until now I do this in two steps :
1) resize to the huge size
2) cut slices

with the mpc-format which is by far the fastest with this amount of pixels
I need lots of memory (which is ok, I have 132GB of Ram) but also lots of time.
only the resize sometimes takes up to 5 minutes, and this is on a 32core Xeon.

So I wonder if I could to it the other way round.
1) cut slices on the original image
2) enlarge the slices

But here comes my problem and question:

Whith the standard resize method I do some kind of bicubicle interpolation (please correct me if this is wrong!)
When I slice first, the border pixels will be interpolated different to the result I would get with "neighbors".
After this kind of operation you can see the cutting line when you put the slices together again.

What I need to know is, how many neighbors do I need (and cut away after resize) to have the same
result as I would get with the whole image.
I assume it still will be much faster to 1) slice with overlap 2) cut borders 3) resize
to have the same result as I get now with my time and memory consuming method.

Please feel free to make any further suggestions.

Thanks or your help!
Roland
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: number of neighbors

Post by fmw42 »

If you are doing standard bicubic (Keys Cubic Convolution or Catrom interpolation), then for each output pixel it takes a special weighted average of 4 intput pixels. For other interpolation methods it depends upon the number of lobes involved. The default upsampling resize is I believe Mitchell. See http://www.imagemagick.org/Usage/filter/
robuntu
Posts: 41
Joined: 2012-01-22T10:56:10-07:00
Authentication code: 8675308

Re: number of neighbors

Post by robuntu »

Hi fmw42,
nice to see that you are helping on every taskes :D

Yes, the Mitchell is the standard an after testing some options I do agree that Mitchell is the best choice for me, too.
So I just use the standard.
When you say one output pixel uses 4 input pixel, is this one each on top, bottom, left and right or
is it not that easy?
However it sounds to be save to use an overlap of 5 pixels and to cut just these 5 pixels per strip after resize.
That could increase the speed by the times of 8 for me, which would be great!
(Resize uses not more then 4 cores, so I can resize 8 strips in parallel with the same
amount of memory that I used before for the whole image)
So again: thanks for your help!

Roland
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: number of neighbors

Post by fmw42 »

Clarification:

Bilinear use a 2x2 array of points to do the interpolation. It takes fractional pixel coordinates in the output and interpolates linear horizontally twice using the 4 input pixels and then 1 more time vertically.

In cubic convolution it does something similar, but interpolates using a 4x4 array of input pixels. The interpolation is done 4 times horizontally and then 1 time vertically, but is not linear.

I am not sure what Mitchell is doing, but I suspect it is similar in using a 4x4 array of input pixels for each output coordinate. I suspect the weights are different. However, if one specifies more lobes, then it probably involves a larger input array.

Anthony is the best person to ask, since he wrote the code.
User avatar
Dane Vandeputte
Posts: 14
Joined: 2012-07-01T18:26:53-07:00
Authentication code: 13
Location: Illinois, USA

Re: number of neighbors

Post by Dane Vandeputte »

If you're using the default interpolation, then you'll need to pad each slice of the original image with 2 pixels on each side. After a slice has been enlarged, you'll then need to crop off 2*scale pixels on each side. For example, if scale = 16, meaning that each dimension will become 16 times larger, you'll need to crop off 2*16 = 32 pixels on each side. One problem that can arise is if scale is not a whole number. For example, if scale = 16.3, then you'd need to crop off 2*16.3 = 32.6 pixels on each side, which isn't exactly possible, since you can't crop off a partial pixel. In this example, you could probably round 32.6 to 33 and not have a noticeable seam. The larger scale is, the less noticeable a seam will be, but it will always be best if scale is a whole number.
Digital image processing and photography enthusiast :)
Post Reply