【问题标题】:How to crop Top, Left, Bottom, and Right boundaries in an image?如何裁剪图像中的上、左、下和右边界?
【发布时间】:2014-04-25 03:34:39
【问题描述】:

我正在尝试裁剪下图的顶部、左侧、底部和右侧边界。

所以,基本上,我正在寻找将上面的图像作为输入并输出这些图像的东西:

可以在MATLAB中使用houghlines检测直线及其尺寸,但是如何找到图像中凸块和凹块的位置?我尝试使用regionpropsextrema 属性,但它不会检测到凹曲线(只给出凸曲线的极值点。)我需要找出凹/凸曲线中的最低/最高点但我不知道该怎么做。不过,我已经弄清楚了之后的步骤;一旦我知道它们,我可以轻松地使用imcrop 裁剪出各自的边界。

【问题讨论】:

  • 这是你的真实形象吗?那么你的图像真的是黑白的吗?因为如果是这样,就很简单,只要找到直线的交点,然后在相应的子阵列中找到最后一个/第一个白色像素;无需求助于特征检测。
  • 哦,哇...我会尝试,但 Divakar 的方法运行良好。谢谢你的提示;深夜编码会影响大脑!
  • @user1106340 我想这就是我所做的,简单的数学,没有复杂的测量。

标签: image matlab image-processing crop edge-detection


【解决方案1】:

代码

%%// Tolerance in percentage for the outliers/noise in the image because 
%%// of which the edges are not perfectly vertical or horizontal and 
%%// the ovalish blobs are not "round" enough
f=2;

%%// Read in your image
img = im2bw(imread('patt1.png'));

%%// Main processing
sum1 = sum(img,1);
box_startx = find(sum1>0.33*size(img,1),1);
box_stopx = size(img,2) - find(fliplr(sum1)>0.33*size(img,1),1) + 1;

sum2 = sum(img,2)'; %'
box_starty = find(sum2>0.33*size(img,2),1);
box_stopy = size(img,1) - find(fliplr(sum2)>0.33*size(img,2),1) + 1;

blob_leftx = find(sum1>(1-0.01*f)*max(sum1),1);
blob_rightx = size(img,2) - find(fliplr(sum1)>(1-0.01*f)*max(sum1),1) + 1;

blob_topy = find(sum2>(1-0.01*f)*max(sum2),1);
blob_bottomy = size(img,1) - find(fliplr(sum2)>(1-0.01*f)*max(sum2),1) + 1;

top1 = img(1:blob_topy,box_startx+1:box_stopx);
left1 = img(box_starty:box_stopy-1,1:blob_leftx);
bottom1 = img(blob_bottomy:end,box_startx:box_stopx);
right1 = img(box_starty:box_stopy,blob_rightx:end);

%// Debug
figure,
subplot(2,2,1);imshow(top1)
subplot(2,2,2);imshow(bottom1)
subplot(2,2,3);imshow(left1)
subplot(2,2,4);imshow(right1)

输出

【讨论】:

    猜你喜欢
    • 2018-10-24
    • 1970-01-01
    • 2013-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多