3D resize image for BIG image size

3 views (last 30 days)
Youngju Kim
Youngju Kim on 24 May 2024
Edited: Matt J on 29 May 2024
[MAIN QUESTION]
I try to resize (reduce) the image size for further image processing because I can't read whole 3D image data (4176*4176*5856) by small memory. Thus I can't use "imresize3". My another strategy is I can read them separately for all Z and reduce image half in X and Y using "tiffreadVolume" and "imresize". However, it doesn't give me image value that iterpolated in Z. Do you have any idea for this?
[SUB QUESTION]
By trying to code my own "imresize3", I got some examples and coded below but it seems it gives a different result. I guess it is antialiasing process. Do you know how to do antialiasing for images? Is it just filtering?
clc; clear all; close all;
% LOAD IMAGE
s = load('mri');
mriVolumeOriginal = squeeze(s.D);
sizeO = size(mriVolumeOriginal);
% SHOW IMAGE
figure; subplot(131);
slice(double(mriVolumeOriginal),sizeO(2)/2,sizeO(1)/2,sizeO(3)/2);
shading interp, colormap gray; axis image;
title('Original');
% RESIZE IMAGE
f = 0.5; % RESIZE RATIO
mriVolumeResized = imresize3(mriVolumeOriginal,f);
sizeR = size(mriVolumeResized);
% SHOW RESIZED IMAGE (by imresize3)
subplot(132);
slice(double(mriVolumeResized),sizeR(2)/2,sizeR(1)/2,sizeR(3)/2);
shading interp, colormap gray; axis image;
title('Resized (imresize3)');
% NEAREST NEIGHBOR INTERPOLATION (NNI)
% DEFINE THE RESAMPLE SIZE
Col = round(sizeO(1)*f);
Row = round(sizeO(2)*f);
Hig = round(sizeO(3)*f);
%FIND THE RATIO OF THE NEW SIZE BY OLD SIZE
rtR = Row/size(mriVolumeOriginal,1);
rtC = Col/size(mriVolumeOriginal,2);
rtH = Hig/size(mriVolumeOriginal,3);
%OBTAIN THE INTERPOLATED POSITIONS
IR = ceil([1:(size(mriVolumeOriginal,1)*rtR)]./(rtR));
IC = ceil([1:(size(mriVolumeOriginal,2)*rtC)]./(rtC));
IH = ceil([1:(size(mriVolumeOriginal,3)*rtH)]./(rtH));
%ROW_WISE INTERPOLATION
B = mriVolumeOriginal(:,IR,:);
%COLUMN-WISE INTERPOLATION
B = B(IC,:,:);
%HEIGHT-WISE INTERPOLATION
B = B(:,:,IH);
% SHOW RESIZED IMAGE (by nearest neighbor interpolation)
subplot(133);
slice(double(B),sizeR(2)/2,sizeR(1)/2,sizeR(3)/2);
shading interp, colormap gray; axis image;
title('Resized (NNI)');

Answers (1)

Matt J
Matt J on 24 May 2024
Edited: Matt J on 24 May 2024
My another strategy is I can read them separately for all Z and reduce image half in X and Y using "tiffreadVolume" and "imresize". However, it doesn't give me image value that iterpolated in Z. Do you have any idea for this?
Can't you just imresize with respect to Z in a second step, e.g.,
Image0=rand(500,500,200);
Image1 = imresize(Image0,'OutputSize',[100,100]); %Or, do it slice-by-slice
Image2 = imresize3(Image1,[100,100,40]); %final image
whos Image*
Name Size Bytes Class Attributes Image0 500x500x200 400000000 double Image1 100x100x200 16000000 double Image2 100x100x40 3200000 double
  4 Comments
Youngju Kim
Youngju Kim on 28 May 2024
I can't read whole 3d data. I used tiffreadVolume to read each image slice (i) of whole images (image.tif).
I'm worried about imresize in Z is not equivalent to imresize3.
path = 'C:\image';
file = 'image.tif';
for i = 1:5856
img = tiffreadVolume(fullfile(path,file),...
"PixelRegion",{[1 1 inf], [1 1 inf], [i i]});
img_bin2 = imresize(img,0.5);
end
Error using tiffreadVolume (line 43)
File "C:\image/image.tif" does not exist.
Matt J
Matt J on 28 May 2024
Edited: Matt J on 29 May 2024
I can't read whole 3d data. I used tiffreadVolume to read each image slice (i) of whole images (image.tif).
To implement my proposal, you do not have to read in the whole data at its original size:
path = 'C:\image';
file = 'image.tif';
C=cell(1,5856);
for i = 1:5856
img= tiffreadVolume(fullfile(path,file),...
"PixelRegion",{[1 1 inf], [1 1 inf], [i i]});
C{i} = imresize(img,1/8);
end
C=cat(3,C{:}); [m,n,p]=size(C,3);
img_final=imresize3( C , [m,n,p/8] ); clear C
I'm worried about imresize in Z is not equivalent to imresize3.
They seem to be equivalent in the test below, but why does it matter if there are small differences?
Image0=rand(500,500,200);
Image1 = imresize(Image0,'OutputSize',[100,100]);
Image2a = imresize3(Image1,[100,100,40]); %final image - version 1
Image2b = imresize3(Image0,[100,100,40]); %final image - version 2
difference= max(abs(Image2a-Image2b), [],'all')
difference = 0

Sign in to comment.

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!