mg = im2double(imread('http://i.stack.imgur.com/ZuiEt.jpg')); % read image and convert it to double in range [0..1]
b = sum( (1-img).^2, 3 ); % check how far each pixel from "white"
% display
figure; imshow( b > .5 ); title('non background pixels');
% use regionprops to get the bounding box
st = regionprops( double( b > .5 ), 'BoundingBox' ); % convert to double to avoid bwlabel of logical input
rect = st.BoundingBox; % get the bounding box
% display
figure; imshow( img );
hold on; rectangle('Position', rect );
我使用此代码裁剪矩形图像,但它不起作用。有什么问题?
答案 0 :(得分:0)
在第一行," mg"应该是" img",我从你的网址中删除了额外的空格。完成这些更改后,您的代码生成了一个完美的边界框。
当您声称代码不起作用时,究竟是什么问题?