フィルターのクリア

How to detect and crop boundry of the given image deleting unwanted space?

1 回表示 (過去 30 日間)
Indunie Florence
Indunie Florence 2014 年 5 月 31 日
コメント済み: Ali Haider 2016 年 2 月 22 日
I want to crop the "Capture.JPG" image from "1.jpg"(left image=>right image)
I used the imcrop but it doesn't gave me the desired image.
My code is given below. Code requires two folders "Testing Images" and "Preprocess Testing Images".
code :-
Imges = dir('Testing Images\*jpg');
InputSet=[];
OutputSet=[];
for i = 1:numel(Imges)
filename = strcat('Testing Images\',Imges(i).name);
I=imread(filename);
Igray = rgb2gray(I);
imwrite(Igray,strcat('Preprocessed Testing Images\GrayScale',int2str(i),'.jpg'));
Ibw = im2bw(Igray,graythresh(Igray));
imwrite(Ibw,strcat('Preprocessed Testing Images\Binary',int2str(i),'.jpg'));
Ibwn=wiener2(Ibw,[5 5]);
imwrite(Ibwn,strcat('Preprocessed Testing Images\AfterNoise',int2str(i),'.jpg'));
Iedge = edge(Ibwn,'canny');
imwrite(Iedge,strcat('Preprocessed Testing Images\AfterEdge()',int2str(i),'.jpg'));
se = strel('arbitrary',2);
Iedge2 = imdilate(Iedge, se);
imwrite(Iedge2,strcat('Preprocessed Testing Images\AfterImdilate()',int2str(i),'.jpg'));
Ifill= imfill(Iedge2,'holes');
imwrite(Ifill,strcat('Preprocessed Testing Images\AfterImfill()',int2str(i),'.jpg'));
IfillInvert=imcomplement(Ifill);
imwrite(IfillInvert,strcat('Preprocessed Testing Images\AfterImInvert()',int2str(i),'.jpg'));
Ifinal1 = bwareaopen(IfillInvert,100);
[Ilabel num] = bwlabel(Ifinal1);
Iprops = regionprops(Ilabel);
Ibox = [Iprops.BoundingBox];
Icrop = imcrop(I,Ibox);
imwrite(Icrop,strcat('Preprocessed Testing Images\AfterCrop1()',int2str(i),'.jpg'));
end
  7 件のコメント
Indunie Florence
Indunie Florence 2014 年 6 月 1 日
no, It doesn't crop above image correctly. Actually above code is a testing code for cropping. Your code is working to the given image by me. It is a very clear card. According to my target I use images with some noises. After some functions worked, it produces a image without boundary. I want to crop it too. Your code didn't work in this situation.
Can you help me.Image is given below. It is in binary mode.
Image Analyst
Image Analyst 2014 年 6 月 1 日
It's a different card so will require a different algorithm. Since it's not a green box, you need to invert the image, then call bwconvhull(), then bwlabeland regionprops, finally imcrop. Give it a try.

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

採用された回答

Image Analyst
Image Analyst 2014 年 5 月 31 日
Try the attached test.m file to produce this image.
  1 件のコメント
Ali Haider
Ali Haider 2016 年 2 月 22 日
Hi,
I want to crop text in bounding box from an image. plz help me out in this.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by