Image Down-sizing

8 views (last 30 days)
Raymond Walter
Raymond Walter on 30 Dec 2019
Edited: Image Analyst on 31 Dec 2019
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?

Answers (2)

Matt J
Matt J on 30 Dec 2019
Edited: Matt J on 30 Dec 2019
I am using the command B=resize(A, [13 13])
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,
newImage=sepblockfun(yourImage,[5,5],'mean')
  4 Comments
Raymond Walter
Raymond Walter on 31 Dec 2019
I attached my 65x65 image. Here's my code:
data65=imread('image65.bmp');
data13=imresize(data65, [13 13]);
I'd like to know why data13(1,1)=83.
Matt J
Matt J on 31 Dec 2019
Edited: Matt J on 31 Dec 2019
It's easier to explain with this modified example, in which I add some noise to your image, and turn off anti-aliasing.
data65=double(imread('image65.bmp'))+rand(65);
[X,Y]=meshgrid(1:65);
Xr=imresize(X,[13,13],'bilinear','Antialiasing',0);
Yr=imresize(Y,[13,13],'bilinear','Antialiasing',0);
data13=imresize(data65, [13 13],'bilinear','Antialiasing',0);
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.

Sign in to comment.


Image Analyst
Image Analyst on 30 Dec 2019
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.
  5 Comments
Image Analyst
Image Analyst on 31 Dec 2019
Edited: Image Analyst on 31 Dec 2019
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.
Matt J
Matt J on 31 Dec 2019
Edited: Image Analyst on 31 Dec 2019
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.
data=(-3:3).*[1;1]
data0 = imresize(data,[2,3],'bilinear','Antialiasing',0)
data1 = imresize(data,[2,3],'bilinear','Antialiasing',1)
data =
-3 -2 -1 0 1 2 3
-3 -2 -1 0 1 2 3
data0 =
-2.3333 0 2.3333
-2.3333 0 2.3333
data1 =
-2.25 -2.7756e-17 2.25
-2.25 -2.7756e-17 2.25

Sign in to comment.

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!