How to detect and crop boundry of the given image deleting unwanted space?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Indunie Florence
el 31 de Mayo de 2014
Comentada: Ali Haider
el 22 de Feb. de 2016
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".
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/163579/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/163580/image.jpeg)
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 comentarios
Image Analyst
el 1 de Jun. de 2014
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.
Respuesta aceptada
Image Analyst
el 31 de Mayo de 2014
Try the attached test.m file to produce this image.
![](https://www.mathworks.com/matlabcentral/images/broken_image.png)
1 comentario
Ali Haider
el 22 de Feb. de 2016
Hi,
I want to crop text in bounding box from an image. plz help me out in this.
Más respuestas (0)
Ver también
Categorías
Más información sobre Image Segmentation and Analysis en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!