Crop an image using coordinates

8 ビュー (過去 30 日間)
Anonymous26
Anonymous26 2019 年 11 月 2 日
編集済み: Anonymous26 2019 年 11 月 27 日
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?
Thanks!
  4 件のコメント
darova
darova 2019 年 11 月 2 日
you have data (x,y) or only image (pixels)?
Anonymous26
Anonymous26 2019 年 11 月 2 日
I only have the image.

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

採用された回答

Image Analyst
Image Analyst 2019 年 11 月 2 日
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, :)
imshow(croppedImage);
drawnow;
end
  11 件のコメント
Image Analyst
Image Analyst 2019 年 11 月 4 日
It should only get to that line if it's an RGB image. What does this say?
ndims(grayImage)
whos grayImage
[rows, columns, numberOfColorChannels] = size(grayImage)
Don't use semicolons and look to see what it reports to the command window.
Anonymous26
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!

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

その他の回答 (1 件)

darova
darova 2019 年 11 月 2 日
Here is an attempt
clc,clear
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
subplot(2,2,i)
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
end
im assuming the original image has no those circles
1Capture.jpg
  2 件のコメント
Anonymous26
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.
darova
darova 2019 年 11 月 3 日
Do you like my idea?

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

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by