简体   繁体   中英

How to rescale the intensity range of a grayscale 3 dimension image (x,y,z) using Matlab

I can't find information online about the intensity rescaling of a 3D image made of several 2D images.

I'm looking for the same function as imadjust which only works for 2D images.

My 3D image is the combination of 2D images stacked together but I have to process the 3D image and not the 2D images one by one.

I can't loop imadjust because I want to process the images as one, to consider all the information available, in all directions.

For applying imadjust for set of 2D grayscale images taking the whole value into account, this trick might work

a = imread('pout.tif');  
a = imresize(a,[256 256]);   %// re-sizing to match image b's dimension
b = imread('cameraman.tif');

Im = cat(3,a,b);     
%//where a,b are separate grayscale images of same dimensions
%// if you have the images separately you could edit this line to
%// Im = cat(2,a,b);
%// and also avoid the next step

%// reshaping into a 2D matrix to apply imadjust
Im = reshape(Im,size(Im,1),[]);

out = imadjust(Im);     %// applying imadjust

%// finally reshaping back to its original shape
out = reshape(out,size(a,1),size(a,2),[]);  

To check:

x = out(:,:,1);
y = out(:,:,2);

As you could see from the Workspace image, the first image (variable x ) is not re-scaled to 0-255 as its previous range (variable a ) was not near the 0 point.

WorkSpace:

在此处输入图片说明


Edit: You could do this as a one-step process like this: (as the other answer suggests)

%// reshaping to single column using colon operator and then using imadjust
%// then reshaping it back
out = reshape(imadjust(Image3D(:)),size(Image3D));

Edit2:

As you have image as cell arrays in I2 , try this:

I2D = cat(2,I2{:})

The only way to do this for 3D image is to treat the data as a vector and then reshape back.

Something like this:

%create a random 3D image.
x = rand(10,20,30);

%adjust intensity range
x_adj = imadjust( x(:), size(x) );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM