Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crop an image in Matlab

Tags:

image

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.

like image 238
Jamal Zafar Avatar asked Apr 03 '11 07:04

Jamal Zafar


3 Answers

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,:);
like image 151
David Brown Avatar answered Oct 06 '22 17:10

David Brown


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.

like image 35
Roy T. Avatar answered Oct 06 '22 18:10

Roy T.


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)
like image 45
Payam Ahmadvand Avatar answered Oct 06 '22 19:10

Payam Ahmadvand