# How can I rescale an image while not changing the dimension of the image?

##### 1 Comment

### Answers (4)

##### 7 Comments

##### 2 Comments

I think this guy wanted something very similar to my actual problem.

Now I needed a function which can zoom in/out of an image, and keeps the original size of the matrix. The second requirement was that the center pixel should remain at the same position. This is what I use now:

function OutPicture = HardZoom(InPicture, ZoomFactor)

if ZoomFactor == 0 OutPicture = []; return; end if ZoomFactor < 0 InPicture = rot90(InPicture, 2); ZoomFactor = 0 - ZoomFactor; end if ZoomFactor == 1 OutPicture = InPicture; return; end xSize = size(InPicture, 1); ySize = size(InPicture, 2); xCrop = xSize / 2 * abs(ZoomFactor - 1); yCrop = ySize / 2 * abs(ZoomFactor - 1); zoomPicture = imresize(InPicture, ZoomFactor); if ZoomFactor > 1 OutPicture = zoomPicture( 1+xCrop:end-xCrop, 1+yCrop:end-yCrop ); else OutPicture = zeros(xSize, ySize); OutPicture( 1+xCrop:end-xCrop, 1+yCrop:end-yCrop ) = zoomPicture; end

end

##### 0 Comments

##### 0 Comments

### See Also

### Products

### Community Treasure Hunt

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

Start Hunting!