3D resize image for BIG image size
3 次查看(过去 30 天)
显示 更早的评论
[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)');
0 个评论
回答(1 个)
Matt J
2024-5-24
编辑:Matt J
2024-5-24
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*
4 个评论
Matt J
2024-5-28
编辑:Matt J
2024-5-29
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')
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!