0
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);
我使用此代码来裁剪矩形图像,但它不起作用。哪里不对?删除背景
非常感谢您先生...问题是,它返回我的原始图像没有裁剪。我实际上是在计算机上使用银行券上的代码,而不一定是URL图像。 –
我将>更改为<,它的工作原理...谢谢。 –
这当然是可能的 - 不同的图像可能会颠倒前景和背景。但是,您提供的图像无需将“>”更改为“<”。 – Herb