Generating .tiff stack efficiently with a high number of image slice

2 views (last 30 days)
I am dealing with image processing and my goal is apply non-local means filter (NLMF) to a sequence of .tif files. So far, I was successful at creating a sequence with dimensions (mxnxp) with p being the number of slices (in my case p could be over 2000). I then applied the NLMF which creates a filtered matrix with similar dimensions. Now I want to be able to export this filtered file into tiff files again. I have checked the imwrite documentation and it looks promising. Still, I am running into a simple "for" loop problem because of the large dataset handled. All in all, i would like to be able to assign each slice of "out_int" to a im(i) variables so that each im(i) variables can be saved into .tiff files and then appended. Is there a clever way to do that to avoid writing a line for each layer ? I am thinking about something like this :
for i= 1:numFrames im(i) = out_int(:,:,i) end
Then,
imwrite(im1, 'myFile.TIFF') for i = 2:numFrames imwrite(im(i), 'soil3D_filt.TIFF', 'writemode', 'append')
In conclusion, I need some help for steps 6 and 7. I also guess that there is a much more clever way and simple way to achieve my goal ! I would appreciate if someone could help me on this one :). Code used is belowed. The NLMF is the one available on mathworks implemented by Dirk Jan.
%% Step (1) - Required step to compile .c files within MatLab (C/C++ compiler is MinGW-w64 and needs to be installed before hand) % These commands only need to be ran once to generate .mexw64 % mex -v -compatibleArrayDims vectors_nlmeans_single.c % mex -v -compatibleArrayDims image2vectors_single.c % mex -v -compatibleArrayDims vectors_nlmeans_double.c % mex -v -compatibleArrayDims image2vectors_double.c
%% Step (2) - Creating a structure array containing the image sequence by preallocating an m -by- n -by- p array and reading images into the array. fileFolder = fullfile('C:\Users\phalempi\Documents\MATLAB\NLMEANS\soil3d'); dirOutput = dir(fullfile(fileFolder,'soil3D_*.tif')); fileNames = {dirOutput.name}' numFrames = numel(fileNames) I = imread(fileNames{1}); sequence = zeros([size(I) numFrames],class(I)); sequence(:,:,1) = I; for p = 2:numFrames sequence(:,:,p) = imread(fileNames{p}); end
%% Step (3) - 3D-Non-Local Means Filtering (NMLF) of Image Sequence (data must be single or double in the range of [0:1], see NLMF.m) D = squeeze(D); D = double(D); Dmax = max(D(:)) D = D./max(D(:)); Options.verbose=true; Options.blocksize=45; out = NLMF(D);
%% Step (4) - Reconverting data to their original grayvalues and from single to unsigned integers out = out.*Dmax; out_int = uint16(out);
%% Step (5) Comparing the original image against the filtered image figure('NumberTitle', 'off', 'Name', 'Original') imshow3Dfull(sequence_eq) figure('NumberTitle', 'off', 'Name', 'Filtered') imshow3Dfull(out_int)
%% Step (6) - Retrieving each layer im1= out_int(:,:,1) im2= out_int(:,:,2) im3= out_int(:,:,2) im4= out_int(:,:,4) im5= out_int(:,:,5) im6= out_int(:,:,6) im7= out_int(:,:,7) im8= out_int(:,:,8) im9= out_int(:,:,9) % and so forth up to numFrames
%% Step (7) - Saving the .tiff files sequence imwrite(im1, 'myFile.TIFF') imwrite(im2, 'myFile.TIFF', 'writemode', 'append') imwrite(im3, 'myFile.TIFF', 'writemode', 'append') imwrite(im4, 'myFile.TIFF', 'writemode', 'append') imwrite(im5, 'myFile.TIFF', 'writemode', 'append') imwrite(im6, 'myFile.TIFF', 'writemode', 'append') imwrite(im7, 'myFile.TIFF', 'writemode', 'append') imwrite(im8, 'myFile.TIFF', 'writemode', 'append') imwrite(im9, 'myFile.TIFF', 'writemode', 'append') % and so forth up to numFrames

Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!