how to use imwrite for an image sequence

조회 수: 2 (최근 30일)
bhavya vendra
bhavya vendra 2015년 8월 20일
댓글: bhavya vendra 2015년 8월 26일
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

채택된 답변

Image Analyst
Image Analyst 2015년 8월 21일
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
Image Analyst
Image Analyst 2015년 8월 25일
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 2015년 8월 26일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by