필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
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
Sean de Wolski
Sean de Wolski 2012년 9월 26일
편집: Sean de Wolski 2012년 9월 26일
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 2012년 10월 1일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2012년 9월 27일
편집: Image Analyst 2012년 9월 27일
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
Asadullah
Asadullah 2012년 10월 1일
편집: Asadullah 2012년 10월 3일
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
Asadullah
Asadullah 2012년 10월 2일
Hi image analyst,
Looking for your precious advice and guidance please!
Thank you very much

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by