No BSD License  

4.0

4.0 | 3 ratings Rate this file 21 Downloads (last 30 days) File Size: 5.27 KB File ID: #8355

label2rgb3D

by

 

24 Aug 2005 (Updated )

Creates a 4D rgb image from a 3D label image.

| Watch this File

File Information
Description

RGB = LABEL2RGB3D(L) converts a 3D label matrix L, such as returned by WATERSHED, into a color RGB image.
 
RGB = LABEL2RGB3D(L, MAP) defines the colormap to be used in the RGB image. MAP can either be an n x 3 colormap matrix, a string containing the name of a colormap function (such as 'jet' or 'gray'), or a function handle of a colormap function (such as @jet or @gray).

LABEL2RGB3D evaluates MAP so that there is a different color for each region in L.If MAP is not specified, 'jet' is used as the default.
 
RGB = LABEL2RGB3D(L, MAP, ZEROCOLOR) defines the RGB color of the elements labeled 0 in the input label matrix L. ZEROCOLOR can either be an RGB triple, or one of the following: 'y' (yellow), 'm', (magenta), 'c' (cyan), 'r'(red), 'g' (green), 'b' (blue), 'w' (white), or 'k'(black). If ZEROCOLOR is not specified, [1 1 1] is used as the default.
    
RGB = LABEL2RGB3D(L, MAP, ZEROCOLOR, ORDER), controls how colormap colors are assigned to regions in the label matrix. If ORDER is 'noshuffle' (the default), then colormap colors are assigned to the label matrix regions in numerical order. If ORDER is 'shuffle', then colormap colors are pseudorandomly shuffled.
    
Class Support
-------------
    The input label matrix L can have any nonsparse numeric class. It must contain finite nonnegative integers. The output of LABEL2RGB3D is ofclass uint8.

Visualization
-------------
MATLAB does not have the capability to visualize 4D data. But the image can be exported to other softwares for visualization.

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.0.4 (R14SP2)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
21 Apr 2014 Nicolas Broguiere

I would add that the code of Nathan worked for me, thanks ;)

21 Apr 2014 Nicolas Broguiere

Didn't work for me either (Matlab2013b), even though the description looked perfect... thanks for your work, but might need an update. Best,

21 Apr 2014 Nicolas Broguiere  
20 May 2013 Nathan Orloff

function rgbcell = label2rgb3d(lblstack)
%label2rgb3d(lblstack) take a labeled stack and turn it into a truecolor image.
% get all of the unique ind
ind = unique(lblstack);
cmap = jet(numel(ind));
images = stack2cell(lblstack);
rgbcell = cellfun(@(x) im2double(label2rgb(x, cmap, 'k')), images, 'UniformOutput', false);

function images = stack2cell(stack)
%stack2cell(stack) convert a stack of data into a cell array
% Detailed explanation goes here
% See also cell2stack
images = num2cell(zeros(size(stack,3),1));
if numel(size(stack)) == 3 % bw and grayscale images
for ii = 1:size(stack,3)
images{ii} = stack(:,:,ii);
end
elseif numel(size(stack)) == 4 % truecolor data
for ii = 1:size(stack,4)
images{ii} = stack(:,:,:,ii);
end
end
end

function stack = cell2stack(images)
%cell2stack converts a cell array of images to a stack (or cube of images)
% converts a cell array of images to a stack (or cube of images)
p = numel(images);
dims = size(images{1});
stack = zeros([dims,p]);
if numel(dims) == 2 % bw and grayscale images
for ii = 1:p
stack(:,:,ii) = images{ii};
end
elseif numel(dims) == 3 % truecolor data
for ii = 1:p
stack(:,:,:,ii) = images{ii};
end
end

end

This should be all you need to do this. While manipulating multidimensional data I found cell2stack and stack2cell incredibly useful. Also, cellfun is a very fast way to implement many of the image processing routines. HTH- Nate

20 May 2013 Nathan Orloff

I think this might be better. Also, I tried your code and I got a incorrect results, but I didn't really try very hard to make it work.

ind = unique(lblstack);
cmap = jet(numel(ind));
images = cell2stack(lblstack);
rgbcell = cellfun(@(x) label2rgb(x, cmap, 'k'), images, 'UniformOutput', false);

10 Oct 2012 Asadullah

please can you tell me how to export the 4D image from matlab?

25 Mar 2010 Alex Gough  

Contact us