如何显示分割图像?

How to show segmented image?

我有一个阈值矩阵来分割我的图像。这是多阈值分割,所有阈值都已准备就绪。 现在,我怎样才能显示我的分割图像? 在每个时期之间,我希望它具有相同的灰度级。 此代码有误,但会说出我需要的内容。

level = sort(thresholds);
I1 = I(0<I && I<level(1));
I1 = gray1;

I2 = (level(1)<I && I<level(2));
I2 = gray2;

这是我的想象,但我无法将其更改为 matlab 代码。 例如阈值元素的数量是 5

你的意思是这样的吗?:

% read Matlab reference image 
I=imread('coins.png');

% thresholds
gray1=100; % lower limit
gray2=200; % upper limit
I(find(I<gray1))=0; % replace anything less than gray1 with zeros
I(find(I>gray2))=0; % replace anything more than gray1 with zeros
imshow(I);