MATLAB Answers


Crop an image using coordinates

Anonymous26 さんによって質問されました 2019 年 11 月 2 日
最新アクティビティ Anonymous26 さんによって 編集されました 2019 年 11 月 27 日 7:53
I am getting a grid for an image using vertical projection.
I want to crop the image part, within the 2 of the points as one cropping image.
Can someone advice me on this?

  4 件のコメント

@darova : Can you please explain this a bit?
2019 年 11 月 2 日
you have data (x,y) or only image (pixels)?
Anonymous26 2019 年 11 月 2 日
I only have the image.

サインイン to comment.

2 件の回答

Image Analyst
Answer by Image Analyst
on 2 Nov 2019
 Accepted Answer

I would use regionprops() to find the start and stop of each non-zero segment, then crop. Something like (untested)
props = regionprops(verticalProfile, 'PixelIdxList');
for k = 1 : length(props)
row1 = props(k).PixelIdxList(1, 1)
row2 = props(k).PixelIdxList(1, end)
croppedImage = grayImage(row1:row2, :)

  11 件のコメント

Thank you for your response.
When i am trying the code, i am getting the following error sir.
Index in position 3 exceeds array bounds (must not exceed 1).
Error in Untitled114 (line 17)
grayImage = grayImage(:, :, 3);
Image Analyst
2019 年 11 月 4 日
It should only get to that line if it's an RGB image. What does this say?
whos grayImage
[rows, columns, numberOfColorChannels] = size(grayImage)
Don't use semicolons and look to see what it reports to the command window.
Anonymous26 2019 年 11 月 8 日
Thank you so much for your support. I made some modifications in the code and made it work, according to my need.
Thanks a lot again!

サインイン to comment.

Answer by darova
on 2 Nov 2019

Here is an attempt
I = imread('Capture.jpeg');
I1 = im2bw(I); % convert to binary
I2 = bwareaopen(~I1,100); % remove numbers (small areas)
[row,col] = find(I2);
I3 = I2*0;
h = 1; % crop thickness
ii = row(1)+h:row(end)-h;
jj = col(1)+h:col(end)-h;
I3(ii,jj) = I2(ii,jj); % crop
I4 = bwareaopen(I3,200); % remove small areas
[L,n] = bwlabel(I4); % label image
for i = 1:4
I5 = L == i; % find part of a curve
I6 = imdilate(I5,ones(5)); % highlight the part
II = cat(3,~I6,I1,I1)*255;
imshow(II) % show original image and part of a curve
im assuming the original image has no those circles

  2 件のコメント

Anonymous26 2019 年 11 月 3 日
My image is not the attached one. That is the gride i got for the original image.
After getting that gride only i am trying to crop the image using the y = 0 points.
2019 年 11 月 3 日
Do you like my idea?

サインイン to comment.

Translated by