Effacer les filtres
Effacer les filtres

saving multilabeled RGB image stack as Text(.txt) file

2 vues (au cours des 30 derniers jours)
Asadullah
Asadullah le 5 Oct 2012
Hi All
I have a stack of 200 microstructure images, the grains in images have been labeled by using 3D watershed segmentation technique and then converted to RGB by label2rgb() function with 'colorcube' as colormap. I have used the following code to save this dataset as text file, but this code only saves the voxel information of each 3D label to text file but not the color of each label(when i visualized by using this resulting text file then it seems like a grayscale image). I do not know how to save this 3D dataset to text file which contain information of each 3D label along with its color, please help me. The code i am using is:
clc;
clear all;
n=200;
fidIn=0;
fidOut=fopen('labeled.txt', 'w');
for i=1:n
strFileName=strcat('section',num2str(i),'.tiff');
% here 'section' is the colored RGB image
fidIn=imread(strFileName);
[M,N]=size(fidIn);
x = repmat('%d ',1,(N-1));
fprintf(fidOut,[x,'%d\n'],fidIn);
end
fclose(fidOut);
Any help will be highly appreciated.
Thanks

Réponse acceptée

Image Analyst
Image Analyst le 5 Oct 2012
I don't know what that code is but it doesn't seem related to what you said - no label2rgb() call, etc.
Basically, just scan each colored image writing it's values
fid = fopen('labeled.txt', 'wt'); % Note: wt.
for row = 1 : rows
for col = 1 : cols
value = labeledImage(row, column);
fprintf(fid, '%d %d %d %f %f %f\n', row, col, value, colorMap(value, 1), colorMap(value, 2), colorMap(value, 2),);
end
end

Plus de réponses (0)

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by