how to use imwrite for an image sequence

2 visualizzazioni (ultimi 30 giorni)
Hello, I have been using a special file format that processes image sequence and I have a stack of images in a 3D file format. I have been using a custom matlab code that reads the 3d file and I can open all the images in the sequence using 'imshow' command but I am not sure how to save all the images I have opened sequentially without having to do it manually. How can I call these files I am opening using 'imshow' as a variable? This is my code: A= WURead3D('trialresults_000900.wu'); i=68; for k=1:i figure,imshow(A(:,:,k),[]); title(sprintf('900 # %d',k)); end

Risposta accettata

Image Analyst
Image Analyst il 21 Ago 2015
Try this:
A= WURead3D('trialresults_000900.wu');
folder = pwd; % or whatever.
numSlices = size(A, 3);
numRows = ceil(sqrt(numSlices));
for k = 1 : size(A, 3)
subplot(numRows, numRows, k);
imshow(A(:,:,k),[]);
drawnow;
caption = sprintf('900 # %d', k);
title(caption, 'FontSize', 30);
baseFileName = sprintf('Slice %d.png', k);
fullFileName = fullfile(folder, baseFileName);
imwrite(A(:,:,k), fullFileName);
end
  16 Commenti
Image Analyst
Image Analyst il 25 Ago 2015
What is class(a)? I'm assuming it will be either 'uint8' or 'uint16' because you're using imwrite() but it appears that it might be 'double', in which case you can't use imwrite on "a" - you'd have to convert it first.
bhavya vendra
bhavya vendra il 26 Ago 2015
Is there another function I could use instead of imwrite that would perform the same task on 'double' images? I converted the .wu files to .mat first and performed the task and it still shows that my matrix A is a double and my a is also a double. Please look at my code and see if I am not doing something right.
clear all
clc
A= WURead3D('resultstrial2sample1.wu');
folder = 'C:\Users\bvendra\Desktop\research\results\bhavya_growth plate\1microngp_trial2sample1\tiffstackafterCOSMOS';
basematFileName = sprintf('A %d.mat',A);
fullmatfilename = 'C:\Users\bvendra\Desktop\research\results\bhavya_growth plate\1microngp_trial2sample1\tiffstackafterCOSMOS\A.mat';
save(fullmatfilename,'A')
storedstructure=load(fullmatfilename);
A=storedstructure.A;
numSlices = size(A, 3);
numRows = ceil(sqrt(numSlices));
for k = 1 : size(A, 3)
subplot(numRows, numRows, k);
a=(A(:,:,k));
imshow(a,[]);
a1 = A(end,end,k);
drawnow;
caption = sprintf('900 # %d', k);
title(caption, 'FontSize', 30);
baseFileName = sprintf('Slice %d.tif',k);
fullFileName = fullfile(folder, baseFileName);
%colormap default
map=gray(256);
%a = intmax('double')*a/ max(a(:));
%a = uint16(a);
imwrite(a,map,fullFileName,'Compression','none','Resolution',[96,96]);
A2Drecalled = imread(fullFileName);
a2 = A2Drecalled(end,end);
fprintf('For plane %d, a1=%f, a2=%f\n', k, a1, a2);
end

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by