Why are my saveas binary images only black?

8 ビュー (過去 30 日間)
Veronika
Veronika 2017 年 4 月 9 日
コメント済み: Veronika 2017 年 4 月 10 日
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 Center および File ExchangeImage Processing and Computer Vision についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by