我如何更改此操作imshowim16,[WC-WW / 2,WC + WW / 2];在matlab中的变量?

问题描述

我想将操作 this.websocket.orders$ .pipe( tap(orders => { if (this.markers.length !== orders.length) this.resetMarkers(orders); else this.updateMarkers(orders); }),switchMapTo( timer(X * 1000).pipe(() => { // reset markers here // timer gets reset on each new emitted event }) ) ) .subscribe() 保存到一个新变量中。这是一张我要显示一定范围的图像,但是我不想使用imshow(im16,[WC-WW/2,WC+WW/2]);,我只想保存具有WC-WW /操作强度窗口一定范围的新图像。 2,WC + WW / 2。

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

解决方法

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,2)
imshow(im,[low,high])
title('Original scaled with imshow')
% Show the new reranged image
subplot(1,3)
imshow(im1)
title('New image')