% 读取图像
I = imread('your_image.png');
% 转换图像为灰度
I_gray = rgb2gray(I);
% 设置阈值的数量
num_thresholds = 2; % 例如,分割成3部分(两个阈值)
% 使用multithresh得到最佳阈值
thresh = multithresh(I_gray, num_thresholds);
% 应用阈值进行分割,quantize操作可以根据阈值将图像分割成若干个部分
seg_I = imquantize(I_gray, thresh);
% 显示结果
figure;
imshow(seg_I, []);
colormap(gca, parula(3)); % 使用parula颜色图以不同颜色显示不同的区域
title('多阈值分割结果');
01-26
08-23