MI=size( I) %Find the original image IAnd display in the command window ReduceI=imresize( I, 0.5) %Original image Inarrow 0.5timesĮnlargeI=imresize( I, 1.5) %Original image Ienlarge 1.5times I=rgb2gray(imread( 'Campus-scenery2sk.JPG'))
#Matlab resize image code
I have suggested to the development team that they make this kind of computation easier in the future, possibly by using the spatial referencing objects that have recently been introduced in the Image Processing Toolbox.The function code of Matlab is as follows: clc
I'll illustrate with a 181-by-361 image of random values. You can use the 'XData' and 'YData' parameters when you call imshow to incorporate this information. So the answer to the original question is: _Each pixel is one degree wide, and the upper left pixel is centered at (0.375 degrees, -89.625 degrees). The mapping from $v$ to degrees is $d_v = v/4 - 90.25$. I'll use $y$ as the vertical output-space symbol and $v$ as the vertical input-space symbol. Now let's repeat the process for the vertical coordinates. The equation for that mapping is $d_u = (u-1)/4$. We know that $u=1$ maps to 0 degrees and $u=1441$ maps to 360 degrees. Look at the first few and last few values of u. To answer that question, first convert from output-space coordinates to input-space coordinates. How do those values correspond to degrees? So, in ordinary pixel coordinates, we have an x-axis with values 1:361. The output of imresize(T,0.25) is 181-by-361, so it has 361 columns. Look for this line in imresize.m u = x/scale + 0.5 * (1 - 1/scale) This equation appears directly in the code. In the diagram above, we can see that $x=0.5$ maps to $u=0.5$ and $x=1.5$ maps to $u=4.5$.įor a general scale factor $s$, here's the equation:
Here's what the geometrical mapping looks like when shrinking by a factor of 4: I'll use the symbol $u$ to represent the input-space coordinate and $x$ to represent the output-space coordinate. Let's get more specific about the coordinate mapping by looking at just one dimension. The 4-pixel by 4-pixel outlined square region on the left geometrically maps exactly to the 1-pixel by 1-pixel square region on the right. The diagram below illustrates the mapping between a region in the input image and the corresponding region in the output image. I think that most people would expect the output image to be 2-by-2. Suppose you have an 8-by-8 image, and you want to shrink it by a factor of 4. I've personally wrestled enough with image resizing over years to know that there's more than one way to precisely interpret the phrase "shrink by a factor of 4." So let me show you exactly what's happening with imresize. This is a really good question that I would be worth exploring in a blog post. If I call imresize(T,0.25) to shrink the image by a factor of 4, what is the geometry of the result in terms of degrees? Is it 0:360 along the x-axis and -90:90 along the y-axis? The y-axis goes from -90 to 90 degrees, also in steps of 0.25 degrees. The x-axis goes from 0 to 360 degrees in steps of 0.25 degrees. I have a 721x1441 matrix, T, of temperature values. This question landed in my inbox recently: