对图像进行二值化时遇到问题:
图片中的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