我如何更改此操作 imshow(im16,[WC-WW/2,WC+WW/2]);变成matlab中的变量?

How I can change this operation imshow(im16,[WC-WW/2,WC+WW/2]); into a variable in matlab?

我想将操作 imshow(im16, [WC-WW/2,WC+WW/2]); 保存在一个新变量中。这是一张我正在显示一定范围的图像,但我不想使用imshow(),我只想保存一个具有一定强度范围window的新图像操作结果WC-WW/2,WC+WW/2.

我正在 Matlab 中处理 CT 图像(png 格式),并调整 window 宽度和 window 水平。

imshow(im16,[WC-WW/2,WC+WW/2]) 所做的是将 im16 中强度低于 WC-WW/2 的每个像素设为黑色 (0),强度高于 WC+WW/2 的每个像素设为白色 ( 255),然后重新缩放剩余的像素。 一种方法是:

im = imread('corn.tif',3); % your image goes here

low = 0.2*255; % lower intensity that you want to put to black (WC-WW/2)
high = 0.8*255; % upper intensity that you want to put to white (WC+WW/2)

im1 = double(im); % turn into double
idxlow = im1 <= low; % index of pixels that need to be turned to black
idxhigh = im1 >= high; % index of pixels that need to be turned to white
im1(idxlow) = 0; % black
im1(idxhigh) = 255; % white
im1(~idxlow & ~idxhigh) = im1(~idxlow & ~idxhigh) - min(im1(~idxlow & ~idxhigh),[],'all'); % rescale low values
im1(~idxlow & ~idxhigh) = im1(~idxlow & ~idxhigh).*255./max(im1(~idxlow & ~idxhigh),[],'all'); % rescale high values
im1 = uint8(im1); % turn back into uint8 (or your initial format)

只是为了检查:

figure
hold on
% Show the original image
subplot(1,3,1)
imshow(im)
title('Original')
% Show the original image reranged with imshow()
subplot(1,3,2)
imshow(im,[low,high])
title('Original scaled with imshow')
% Show the new reranged image
subplot(1,3,3)
imshow(im1)
title('New image')