【问题标题】:Binarization image does not have good effect二值化图像效果不佳
【发布时间】:2017-08-29 12:30:37
【问题描述】:

我在二值化图像时遇到问题:

图片中的walker在二值化后丢失。有人可以提供帮助吗?这是我使用的代码:

clc;
clear;
video = VideoReader('C:\Users\Small_Bird\Desktop\ch02_20170323193606~2.avi');
nFrames = video.NumberOfFrames;
H = video.Height;
W = video.Width;

Rate = video.Preallocate movie structure.

for frameNum = 3500:nFrames
     P = read(video,frameNum);
     grayImage=rgb2gray(P);
     cannyEdge=edge(grayImage,'canny');
     [m,n]=size(grayImage);
     for i=1:m
         for j=1:n
             if 1==cannyEdge(i,j)
                 h(i,j)=grayImage(i,j)+3;
             else 
                 h(i,j)=grayImage(i,j);
             end
         end
     end

     thresh=graythresh(h);
     I2=im2bw(h,thresh);   
     subplot(2,2,1);
     imshow(grayImage),title('original image');
     subplot(2,2,2);
     imshow(cannyEdge),title('image after extracting edge');
     subplot(2,2,3);
     imshow(h),title('image after strengthening edge');
     subplot(2,2,4);
     imshow(I2),title('image after binaryzation'); 
end

【问题讨论】:

  • 代码显示出来了。

标签: matlab image-processing image-thresholding


【解决方案1】:

问题在于im2bw 的阈值选择。您正在使用函数graythresh 计算整个图像的全局阈值,结果显示该阈值只能成功地将图像的黑色部分与图像的灰色或更高部分分开。您需要选择一个更高的阈值,可以是用于所有图像的绝对阈值,也可以是根据每张图像的某些特征计算得出的阈值。

如果您有 MATLAB R2016a 或更高版本,则可以选择使用 'adaptive' method 使用 adaptthresh 或 im2binarize(在较新版本中替换 im2bw 函数)计算局部自适应阈值。与简单的全局阈值相比,这可能会给您带来更好的结果。

【讨论】:

  • 似乎包含了所有的边缘黑色像素。但是,还是谢谢你!
猜你喜欢
  • 2016-02-15
  • 1970-01-01
  • 2017-08-27
  • 1970-01-01
  • 1970-01-01
  • 2012-04-13
  • 2018-08-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多