Why are my saveas binary images only black?

1 次查看(过去 30 天)
Dear all,
I have DICOM images, that I convert to binary images and save them into folder. Saving is correct, but these images could be look like that:
but these images look like this:
This is my code:
Folder = 'C:/Users/ced0005/DP/DP_framework/DICOM/slicesCT/';
for k = 1:10 figure(k);
for p = 48:86
filename = fullfile(Folder, sprintf('%06d.dcm', p));
grayImage(:,:,1,p - 47)= dicomread(filename);
grayImage_pater(:,:,1,p - 47)= dicomread(filename);
[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);%ekvalizace pomocí histogramu obrazu
[rows, columns, numberOfColorChannels] = size(grayImage_pater);
if numberOfColorChannels > 1
% Máme barevný obraz, musíme ho převést na černobílý = vybereme zelený kanál
grayImage_pater = grayImage_pater(:, :, 2); % zelený kanál
end
eq_grayImage_pater = histeq(grayImage_pater);
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, 750);
%Roztažení binárního obrazu pro přesnější segmentaci
se = strel('line',5,100);
binaryImage_okoli= imdilate(binaryImage_okoli,se);
imshow(binaryImage_okoli);
temp=['fig',num2str(k),'.png'];
saveas(gca,temp);
end
end
Can you advise me? Please, some simple solution. Thank you for your answers.

回答(1 个)

Image Analyst
Image Analyst 2017-4-9
The graylevel is only 1 so you can't see it. Multiply it by 255 if you want it to be a uint8 image where the "true" pixels show up as white.
  2 个评论
Veronika
Veronika 2017-4-10
I tried multiply image according to you like this:
Folder = 'C:/Users/ced0005/DP/DP_framework/DICOM/slicesCT/';
for k = 1:10 figure(k);
for p = 48:86
filename = fullfile(Folder, sprintf('%06d.dcm', p));
grayImage(:,:,1,p - 47)= dicomread(filename);
grayImage_pater(:,:,1,p - 47)= dicomread(filename);
[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);%ekvalizace pomocí histogramu obrazu
[rows, columns, numberOfColorChannels] = size(grayImage_pater);
if numberOfColorChannels > 1
% Máme barevný obraz, musíme ho převést na černobílý = vybereme zelený kanál
grayImage_pater = grayImage_pater(:, :, 2); % zelený kanál
end
eq_grayImage_pater = histeq(grayImage_pater);
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, 750);
%Roztažení binárního obrazu pro přesnější segmentaci
se = strel('line',5,100);
binaryImage_okoli= imdilate(binaryImage_okoli,se);
imshow(binaryImage_okoli);
uint8Image = uint8(255 * binaryImage_okoli);
temp=['fig',uint8Image(k),'.png'];
saveas(gca,temp);
end
end
This is for now my the best output in this problem. But I don´t know, if it´s completely right, because after one for loop there appears black and white image, but after few seconds changes to black. I don´t know, what is exactly saved, because I can´t see these figures anywhere.
Veronika
Veronika 2017-4-10
I figured it out, that my saved image is fig (file) and constantly being overwritten and I would like to fig1.png, fig2.png,....fig38.png. Can you advise me, how resolve this?

请先登录,再进行评论。

类别

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