Jamal Zafar
Jamal Zafar

Reputation: 2189

Crop an image in Matlab

I want to crop an image from a specific row onwards. Please help me how can I do this. I am a beginner in Matlab.

Upvotes: 6

Views: 23470

Answers (3)

Payam Ahmadvand
Payam Ahmadvand

Reputation: 151

You can use imcrop function in Matlab CropIm = imcrop(I, rectangle); rectangle is a four-element position vector [xmin ymin width height] which indicates the size and position of the crop rectangle.

Im = imread('test.tif');
Im2 = imcrop(Im,[75 68 130 112]);
imshow(Im), figure, imshow(Im2)

Upvotes: 4

David Brown
David Brown

Reputation: 13526

This page has a lot of great info on dealing with images in matlab.

When you load an image in matlab, it is loaded as a MxNx3 matrix. The third dimension stores the RGB values of each pixel. So to crop an image you simply select just the range of rows and columns you want to keep:

cropped_image = image(RowStart:RowEnd,ColStart:ColEnd,:);

Upvotes: 9

Roy T.
Roy T.

Reputation: 9638

See this: http://www.mathworks.com/help/techdoc/creating_plots/f9-47085.html

There is a graph editor icon in the screen where you see your graph, it should look like this: Expanded graph editor button

Press it, you will get a big graph editor, now try pressing on the graph or one of the functions, in the lower right part you can set ranges, this will crop the image.

Upvotes: 4

Related Questions