Zoom and Crop Image (Matrix) - HELP!

32 views (last 30 days)
Hi there, I have 2 questions that pertains to zooming and cropping of an image.
1) Zooming into an image that would make the image twice as large in both height and width and that each pixel in the matrix is replicated to become 4 pixels. Was wondering if this can be accomplished without using any loops or interpolations and the function imresize.
2) Cropping a matrix by selecting a certain area of the image and then cropping it to a certain length and height. Again, I'm wondering how this can be accomplished without using any loops or interpolations and the function imresize. Maybe by removing a certain column and row from the matrix?
Any help on how to create a function for these would be greatly appreciated. :)

Accepted Answer

Image Analyst
Image Analyst on 19 Feb 2015
1. You can use imresize(). Check out its options. See attached demo on zooming. ALso check out the 'InitialMagnification' option to imshow().
2. You can use imcrop(), or regular indexing
subImage = yourImage(row1:row2, col1:col2);
To remove a row
matrix(rowToDelete, :) = [];
  2 Comments
Rohan Nair
Rohan Nair on 19 Feb 2015
Edited: Rohan Nair on 19 Feb 2015
Hi Image Analyst, for number 2), this is my code,
function output = crop(image, uppercorner, height_width)
[x, y] = uppercorner;
[h, w] = height_width;
subImage = image(x,y);
output = subImage(1:h, 1:w);
end
So far what im trying to accomplish is trying to pick a spot on the image defined by uppercorner, then crop a certain length and width defined by height_width. Basically my thinking around is that I pick the upperorner i want then extend out to the length and width given by the input value height_width to get the cropped image, but I get an error saying 'Too many output arguments'
The example I have is as follows im = double(imread('VeniceBW800.jpg'))/255; a = crop(im, [400 500], [100 300]); imshow(a)
Im trying to replicate something like this and any further help would be greatly appreciated!
Thank you for your time.
Image Analyst
Image Analyst on 19 Feb 2015
imcrop just takes one array, not two. It takes [left, top, width, height]. And don't use image as the name of your variable since it's a built-in function name.
subImage = imcrop(yourImage, [x, y, width, height]);

Sign in to comment.

More Answers (0)

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!