How to convert/save a 3D watershed segmented RGB image stack to a .txt file by assigning unique integers to each 3D label

3 views (last 30 days)
Hi everyone,
I have a stack of RGB images which have been labeled by applying 3D watershed algorithm, each grain (region) in the dataset has a unique identifier (color) associated with it. I want to store the information of each 3D labeled grain in a text (.txt) file. As after cancatenation of 2d image sections, each grain(color) takes 3D form and comprises of many voxels. To explain, consider a red color grain comprises of 5 voxels and a green color grain comprises of 4 voxels, then i want to assign a unique integer to every color grain, so i assign for example here the integer '230' to each voxel of red color grain and integer '150' to each voxel of green color grain and...... so on (different integer for different color grain), thus the frmat of the text file would be 230 230 230 230 230 150 150 150 150.......
here 230 230 230 230 230 is for five voxels of red grain and 150 150 150 150 is for four voxels of green grain. similarly, i want to apply this procedure to all the 3D grains in my image stack and save the assigned integers in a .txt file. The dimensions of my sample volume are 400x400x120. some images of my dataset are uploaded here for information http://www.sendspace.com/file/ifu50s . I am fairly new to matlab and searched several times for it solution but unfortunately failed. Can any one guide me please? Any help will be highly appreciated!
Thanks
  2 Comments
Sean de Wolski
Sean de Wolski on 26 Sep 2012
Edited: Sean de Wolski on 26 Sep 2012
I would like to help, but I don't particularly want to download a file from an untrusted source. Can you provide a small example of input/operations/expected outputs?
Walter Roberson
Walter Roberson on 1 Oct 2012
Note: the most-active volunteers will seldom download .rar files. They are more likely to download .zip files, but they prefer plain images posted to a system that allows them to preview what they would be downloading.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 27 Sep 2012
Edited: Image Analyst on 27 Sep 2012
See my color segmentation demos http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862. Or if you're lucky, you can get by with rgb2ind to do the color segmentation. Then, once you've segmented your image into two binary images of all the red particles, and all the green particles, you can multiply the binary images by some number (the intensity that you want them to be like 230 or 150) and recombine with cat(3, r, g, b) to construct your RGB image.
If that's not what you want, then upload two simple 2D images of input and output, to illustrate what you want.
I didn't quite understand what you want since the subject doesn't exactly agree with the body of your message. Looking at your subject line, I'd recommend the function label2rgb() to convert an already-labeled image into an image where the labeled objects have a color, though you'd need to know which object number was which class (red or green).
  15 Comments
Asadullah
Asadullah on 1 Oct 2012
Edited: Asadullah on 3 Oct 2012
I have used colorcube map to apply color to my labeled image stack, thus each 3D label(blob) has a unique color associated with it. i have used the following code to write this colorlabeled dataset to text file(please guide me is this the right code to acheive my goal, as i am new to matlab):
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 as i have shared above
fidIn=imread(strFileName);
[M,N]=size(fidIn);
x = repmat('%d ',1,(N-1));
fprintf(fidOut,[x,'%d\n'],fidIn);
end
fclose(fidOut);
When i visualize this resulting text file then it looks like
please guide me how to modify this code to get the actual color information also.
Thanks

Sign in to comment.

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!