clear_all();
image_name = 'canny_test.png';
% no of pixels discarded on border areas
discard_pixels = 10;
% read image and convert to grayscale
input_image = gray_imread(image_name);
% discard border area
input_image = discard_image_area(input_image, discard_pixels);
% create a binary image
binary_image = edge(input_image,'canny');
imshow(binary_image);
输入
预期结果
实际结果
在这里,我们看到 Canny 边缘检测器正在检测图像的边界线,这不是我的预期结果。
我怎样才能做到这一点?
源代码
function [output_image] = discard_image_area( input_image, pixel_count)
output_image = input_image;
[height, width] = size(input_image);
% discard top
output_image(1:pixel_count, :) = 0;
% discard bottom
h = height - pixel_count;
output_image(h:height, :) = 0;
% discard left
output_image(:,1:pixel_count) = 0;
% discard right
output_image(:,(width-pixel_count):width) = 0;
end
function img = gray_imread( image_name )
I = imread(image_name);
if(is_rgb(I))
img = rgb2gray(I);
elseif (is_gray(I))
img = I;
end
end