如题,求大佬指点
一下是代码
% 读取图像
img = imread('云影图片.png');
% 转换为灰度图像
grayImg = rgb2gray(img);
% 尝试不同的阈值
thresholds = [lbk]100, 150, 200[rbk]; % 可根据需要修改这些阈值
for i = 1:length(thresholds)
threshold = thresholds(i);
% 使用阈值分割来提取水面边界线
bwImg = grayImg > threshold;
% 使用边缘检测算法来找到边界线
% 这里使用Canny边缘检测器
edges = edge(bwImg, 'Canny');
% 找到边缘像素的坐标
[lbk]y, x[rbk] = find(edges);
% 显示结果
figure;
subplot(1, 2, 1);
imshow(img);
title('Original Image');
subplot(1, 2, 2);
imshow(edges);
hold on;
plot(x, y, 'r.', 'MarkerSize', 1);
title([lbk]'Detected Water Surface Boundary (Threshold = ', num2str(threshold), ')'[rbk]);
hold off;
% 输出边界线坐标
disp([lbk]'Detected boundary coordinates (Threshold = ', num2str(threshold), '):'[rbk]);
for j = 1:length(x)
fprintf('(%d, %d)\n', x(j), y(j));
end
end


一下是代码
% 读取图像
img = imread('云影图片.png');
% 转换为灰度图像
grayImg = rgb2gray(img);
% 尝试不同的阈值
thresholds = [lbk]100, 150, 200[rbk]; % 可根据需要修改这些阈值
for i = 1:length(thresholds)
threshold = thresholds(i);
% 使用阈值分割来提取水面边界线
bwImg = grayImg > threshold;
% 使用边缘检测算法来找到边界线
% 这里使用Canny边缘检测器
edges = edge(bwImg, 'Canny');
% 找到边缘像素的坐标
[lbk]y, x[rbk] = find(edges);
% 显示结果
figure;
subplot(1, 2, 1);
imshow(img);
title('Original Image');
subplot(1, 2, 2);
imshow(edges);
hold on;
plot(x, y, 'r.', 'MarkerSize', 1);
title([lbk]'Detected Water Surface Boundary (Threshold = ', num2str(threshold), ')'[rbk]);
hold off;
% 输出边界线坐标
disp([lbk]'Detected boundary coordinates (Threshold = ', num2str(threshold), '):'[rbk]);
for j = 1:length(x)
fprintf('(%d, %d)\n', x(j), y(j));
end
end

