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
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!