Why are my saveas binary images only black?

5 visualizaciones (últimos 30 días)
Veronika
Veronika el 9 de Abr. de 2017
Comentada: Veronika el 10 de Abr. de 2017
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.

Respuestas (1)

Image Analyst
Image Analyst el 9 de Abr. de 2017
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 comentarios
Veronika
Veronika el 10 de Abr. de 2017
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 el 10 de Abr. de 2017
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?

Iniciar sesión para comentar.

Categorías

Más información sobre Image Processing and Computer Vision en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by