Cut an area in the image

Hey everyone;
In fact my problem is I have an image that I want to automatically remove black areas as shown in attachment. http://www.casimages.com/img.php?i=120531055451175771.png What I meant exactly what is extracting the part surrounded by yellow, so I can do processing on that image.
I thought imcrop, but in this case, the selection must be done manually.
thank you

回答 (3 件)

Andrei Bobrov
Andrei Bobrov 2012 年 5 月 31 日

0 投票

use function imcrop from Image Processing Toolbox
Elad
Elad 2012 年 5 月 31 日

0 投票

you can choose top left and bottom left boundaries using range=ginput(2); and then image=image(range(1,2):range(2,2),range(1,1):range(2,1),:);
Image Analyst
Image Analyst 2012 年 5 月 31 日

0 投票

What I would do, assuming your corners of your sheared image touch the borders of the image are to scan each edge of the image looking for non-zero pixels. Then sort the row values and sort the column values of the corner locations. Then you want to go between the 2nd and 3rd values.
row1 = sortedRows(2);
row2 = sortedRows(3);
col1 = sortedCols(2);
col2 = sortedCols(3);
% Now crop
height = row2-row1+1;
width = col2-col1+1;
croppedImage = imcrop(fullImage, [col1, row1, width, height]);

2 件のコメント

nomad nomad
nomad nomad 2012 年 6 月 1 日
The image is the output of a program that the projective transformation of an input image and since I have no prior knowledge of the shape of the image, I can not define the coordinates.
Image Analyst
Image Analyst 2012 年 6 月 1 日
So what? You don't need to. Just scan the borders, like
leftColumn = fullImage(:, 1); % Get column 1
% Find where it's non-zero:
upperLeftRow = find(leftColumn >0, 1, 'first');
Similar for the other 4 corners that touch the border. Where in that are you required to have prior knowledge of any transform that was used to warp the image?

サインインしてコメントする。

質問済み:

2012 年 5 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by