How to resize an image without using imresize in matlab
Asked
Active
Viewed 3.6k times
0
-
4having someone to do your homework wont teach you matlab... If you spend 20-30 minutes reading through the basic documentation regarding matrix operations, notations etc, you'd be surprised how easy it all is... – bla Sep 04 '14 at 21:20
-
Look at Richard Alan Peters II's image processing slides on image resampling: https://ia600307.us.archive.org/7/items/Lectures_on_Image_Processing/EECE253_12_Resampling.pdf - Pay specific attention to slide #34. – rayryeng Sep 04 '14 at 21:31
-
Since @lakesh has given you the code of nearest neighbor interpolation, why don't you try bilinear interpolation and try to impress your teacher (and yourself!)? – Autonomous Sep 05 '14 at 05:53
-
Here's my implementation of bilinear interpolation in MATLAB: http://stackoverflow.com/questions/26142288/how-to-shrink-an-image-without-using-imresize-function-in-matlab/26143655#26143655 – rayryeng Oct 03 '14 at 17:41
1 Answers
8
This code is done using nearest neighbor interpolation.
%# Initializations:
scale = [2 2]; %# The resolution scale factors: [rows columns]
oldSize = size(inputImage); %# Get the size of your image
newSize = max(floor(scale.*oldSize(1:2)),1); %# Compute the new image size
%# Compute an upsampled set of indices:
rowIndex = min(round(((1:newSize(1))-0.5)./scale(1)+0.5),oldSize(1));
colIndex = min(round(((1:newSize(2))-0.5)./scale(2)+0.5),oldSize(2));
%# Index old image to get new image:
outputImage = inputImage(rowIndex,colIndex,:);
You just need to change the scale factor accordingly..

lakshmen
- 28,346
- 66
- 178
- 276
-
6This is good code lakesh, but I wouldn't have posted this because the question sounds like homework. We should let these people do their own homework. I only give solutions if I can clearly see that they have made a good effort and are stuck. This OP hasn't tried anything. I will still vote +1 because this is the correct way to do nearest neighbour interpolation in 2D... or at least one of the correct ways. – rayryeng Sep 04 '14 at 21:28
-
I actually found this answer very helpful. MathWorks is very stingy with toolboxes, and it seems silly to pay for the Image Analysis toolbox just so you can scale an image. – Kenn Sebesta Nov 18 '17 at 00:06
-
Consider trying the FEX file https://www.mathworks.com/matlabcentral/fileexchange/44538-videoresize – Carl Witthoft Jul 22 '19 at 18:56