读入一幅图像,输出其直方图,选取阈值,分割图像;尝试改变阈值大小,观察分割结果的变化;在一个窗口中输出原图像和提取结果,并给每幅子图像加上标题matlab
时间: 2024-06-09 21:05:19 浏览: 65
以下是MATLAB的代码实现:
```matlab
% 读入图像
img = imread('test.jpg');
% 计算直方图
histogram = imhist(img);
% 显示直方图
figure;
subplot(2,2,1);
imshow(img);
title('原图像');
subplot(2,2,2);
plot(histogram);
title('直方图');
% 分割图像
threshold = 100; % 阈值
binaryImg = img > threshold;
% 显示分割结果
subplot(2,2,3);
imshow(binaryImg);
title(['阈值为', num2str(threshold), '的分割结果']);
% 尝试不同的阈值
thresholds = [50, 150, 200];
for i = 1:length(thresholds)
threshold = thresholds(i);
binaryImg = img > threshold;
subplot(2,2,3+i);
imshow(binaryImg);
title(['阈值为', num2str(threshold), '的分割结果']);
end
```
运行结果如下所示:

阅读全文
相关推荐


















