I have a 65 x 65 image that i want to down-size to 13 x 13. I am using the command B=resize(A, [13 13]). I expected the pixels in the output image B to be the average of the 5 x 5 windows but they were not. Exactly how does down-sizing work?
I think you really mean the command imresize(). If so, it will not average pixels together. It just re-interpolates the pixel values at the lattice points of the 13x13 grid.
To do as you've described, you can download sepblockfun and do the down-sampling as follows,
imresize obtains the values of data13(i,j) from 2D bilinear interpolation of data65 at coordinates contained in Xr and Yr. Notice, for example, the following equivalence,
>> i=10;j=12;
>> val1=data13(i,j)
val1 =
32.2264
>> val2=interp2(data65,Xr(i,j),Yr(i,j),'linear')
val2 =
32.2264
The points in Xr, Yr form a lattice of sample locations centered in the original image:
In your case, when you did,
data65=imread('image65.bmp');
data13=imresize(data65, [13 13]);
the result was also influenced by various additional factors: you had anti-aliasing turned on, you were using bicubic interpolation, and your data were uint8 instead of doubles, so the interpolations were being done with integer precision.
Did you look in the documentation for imresize()? That's always a good place to start. You'll see under method that there are bilinear (default), bicubic, and nearest. I think those are rather self explanatory, if not, there's always Wikipedia. And there are further options on the interpolation kernel.
Apparently, bicubic is now the default interpolation method.
But even if bilinear interpolation is manually speciifed, it is not clear to me how the new pixel sizes are chosen. How did the horizontal pixel size go from 1 to 2.25 in the example below? Shouldn't it be 7/3?
I believe if you delve into it, it will come down to whether you're looking at pixels as little boxes that go out to the outer edge (at 0.5 locations), or whether you consider pixels going from center to center.
For example, how long is the stretch of 1's in [0, 1, 1, 1, 0]? What is the distance or width of it from the left 1 to the right 1? Is it 3 (left outside edge to right outside edge -- index 1.5 to 4.5), or is it 2 (center of left 1 to center of right 1 -- index 2 to 4)? You can make an argument either way and neither is wrong. They're just two different ways of looking at it.
It turned out to be more basic than that. I figured out that anti-aliasing needed to be turned off. Once I did that, the resampled pixel values values reflected the expected pixel sizes.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
0 Comments
Sign in to comment.