Can someone help me understand this code? It's a crop function for image processing.

2 ビュー (過去 30 日間)
I'm doing a project on gesture recognition. A part of the code is this function imcrop, as given below. Can someone explain how this works? And also how I can integrate it into the main code?
% MATLAB FUCTION imcrop TO CROP THE CAPTURED IMAGE
function imgout=imgcrop(imgin) %function definition
imgin = imresize(cropimg,[240,240]); %resize the original image
columnsum=sum(cropimg); %find the sum of column entries
rowsum=sum(cropimg'); %find the sum of row entries
q1=1;
q2=240;
q3=1;
q4=240;
for w=1:240 %search for the vertical cropping boundary
if (columnsum(1,w)>=10)
q1=w;
break;
end
end
for w=q1:240 %search for the vertical cropping boundary
if (columnsum(1,w)>=10)
q2=w;
end
end
for w=1:240 %search for the horizontal cropping boundary
if (rowsum(1,w)>=10) q3=w;
break;
end
end
for w=q3:240 %search for the horizontal cropping boundary
if (rowsum(1,w)>=50)
q4=w;
end
end
%crop the image between boundaries and resize to original
imgout=cropimg(q3:q4,q1:q2);
imgout=[zeros(q4-q3+1,160-(q2-q1+1)),imgout;zeros(120-(q4-q3+1),160)];
imgout=imresize(imgout,[120,160]);
imgout=double(imgout); %convert the image type to double for future use

採用された回答

Image Analyst
Image Analyst 2014 年 2 月 3 日
It doesn't work. As soon as it hits the first line
imgin = imresize(cropimg,[240,240]);
it will throw an exception because cropimg is undefined. It looks like something written by a very novice MATLAB programmer to find the rows and columns where the image is bright enough to be retained. Instead of all those for loops, they could simply use find(). Then they pad the image with zeros on the left and right and resize it for some reason. Basically they're masking out dark stuff outside the bounding box but doing it in a very odd way. If you want a masking app, just ask me for a demo.
  3 件のコメント
Anjana Rao
Anjana Rao 2014 年 2 月 7 日
Thank you! :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by