saving multilabeled RGB image stack as Text(.txt) file
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Image Analyst
on 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
More Answers (0)
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!