这里是一个溶液
阈值图像,以便它仅仅是在二元的,容易的,因为这个图象很简单
确定每列中最低像素的位置
通过仅取第n列的最大值来平滑。 如果你只是想要最低点,那么你可以停止在下面的代码第4行!
代码被注释为更详细地:
img = rgb2gray(imread('1.jpg')); % Read image
img = img > 0.5; % Threshold to get binary image
% Get last row where there is a 1 pixel in the image for each column
lastrow = max(repmat((1:size(img,1))', 1, size(img,2)).*img,[],1);
res = 30; % Pixel resolution for line averaging
% Ensure res divides num. columns by padding the end of the vector
lastrowpadded = [lastrow, NaN(1, res - mod(numel(lastrow),res))];
% Reshape into columns of length 'res', then get the max row number
lastrow2 = max(reshape(lastrowpadded,res,[]),[],1);
% Plots
imshow(img);
hold on
plot(1:size(img,2), lastrow, '.')
plo