Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

How to save images into one multipagefile tiff file?

1 vue (au cours des 30 derniers jours)
Veronika
Veronika le 22 Avr 2017
Dear all,
I have this code for creating and saving binary images into one tiff multipagefile. But I have mistake somewhere in for loop, respectively in it´s location.
clc;
close all;
clear;
workspace;
format long g;
format compact;
fontSize = 20;
folder = 'C:/Users/ced0005/DP/DP_framework/DICOM/slicesCT/';
if ~isdir(folder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', folder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(folder, '*.dcm');
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
grayImage= dicomread(fullFileName);
subplot(1, 2, 1);
imshow(grayImage, []);
axis on;
title(baseFileName, 'FontSize', fontSize);
drawnow;
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% % Máme barevný obraz, musíme ho převést na černobílý = vybereme %zelený kanál
grayImage = grayImage(:, :, 2); % zelený kanál
end
eq_grayImage = histeq(grayImage);
% Práh pro vytvoření binárního obrazu okolí
thresholdValue = 900;
binaryImage_okoli = grayImage > thresholdValue;
% Odstranění okolí.
binaryImage_okoli = imclearborder(binaryImage_okoli);
% Vyplnění otvorů.
binaryImage_okoli = imfill(binaryImage_okoli, 'holes');
% Vymazání menších otvorů.
binaryImage_okoli = bwareaopen(binaryImage_okoli, 1150);
% Roztažení binárního obrazu pro přesnější segmentaci
se = strel('line',5,100);
binaryImage_okoli= imdilate(binaryImage_okoli,se);
subplot(1, 2, 2);
imshow(binaryImage_okoli, []);
title('Binarizovaný obraz', 'FontSize', fontSize);
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
drawnow;
baseOutputFileName = sprintf('Binarizace_okoli_%3d.png', k);
fullOutputFileName = fullfile(folder, baseOutputFileName);
imwrite(logical(binaryImage_okoli), fullOutputFileName);
fprintf('Uloženo %s.\n', fullOutputFileName);
*if k == 1
imwrite(binaryImage_okoli,'myMultipageFile.tif')
else
imwrite(binaryImage_okoli,'myMultipageFile.tif','writemode','append')
end*
end
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
set(gcf, 'Name', 'Binarizace testovacích CT skenů', 'NumberTitle', 'Off')
Please, where I have mistake.
Can you advice me? Thank you for your answers.
  2 commentaires
Veronika
Veronika le 22 Avr 2017
Yes, I know, but I don´t have answer.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by