Setting common color maps for categorical images with no ordinal information in the categorical labels
I’m trying to create a common colormap from two different categorical images that are segmentations of brain regions. The labels in "oldsegvis" are an entirely contained subset of the labels in "newsegvis". I’m expecting the same label value (e.g. newseg = 100, oldseg = 100) to return the same color, however, that is not the output behavior I’m observing. I’ve confirmed by looking at the values in the output newsegvis and oldsegvis arrays and by using "Data Tips" that the same values are being assigned different colors. Additionally, in the visualization of the "newsegvis" array, different values are being assigned the same color, which I’ve also confirmed with "Data Tips", even though the number of colors and the number of unique label values are the same. A code snippet is pasted below; I’m sure there’s something simple I’m missing, but would be very appreciative if someone could point it out to me. Thanks!
%% Visualize segmentations
%select section (transverse plane)
newsegvis = squeeze(newvol(:,:,100));
oldsegvis = squeeze(oldvol(:,:,100));
%set colormaps (new segmentations have all old segmentation labels plus
%additional labels)
newsegs = unique(newsegvis);
oldsegs = unique(oldsegvis);
cmap_ov = [0 0 0;rand(length(newsegs)-1,3)];
cmap_orig = cmap_ov(1:length(oldsegs),:);
%visualize segmentations
figure; imagesc(newsegvis); colormap(cmap_ov);
figure; imagesc(oldsegvis); colormap(cmap_orig);I’m trying to create a common colormap from two different categorical images that are segmentations of brain regions. The labels in "oldsegvis" are an entirely contained subset of the labels in "newsegvis". I’m expecting the same label value (e.g. newseg = 100, oldseg = 100) to return the same color, however, that is not the output behavior I’m observing. I’ve confirmed by looking at the values in the output newsegvis and oldsegvis arrays and by using "Data Tips" that the same values are being assigned different colors. Additionally, in the visualization of the "newsegvis" array, different values are being assigned the same color, which I’ve also confirmed with "Data Tips", even though the number of colors and the number of unique label values are the same. A code snippet is pasted below; I’m sure there’s something simple I’m missing, but would be very appreciative if someone could point it out to me. Thanks!
%% Visualize segmentations
%select section (transverse plane)
newsegvis = squeeze(newvol(:,:,100));
oldsegvis = squeeze(oldvol(:,:,100));
%set colormaps (new segmentations have all old segmentation labels plus
%additional labels)
newsegs = unique(newsegvis);
oldsegs = unique(oldsegvis);
cmap_ov = [0 0 0;rand(length(newsegs)-1,3)];
cmap_orig = cmap_ov(1:length(oldsegs),:);
%visualize segmentations
figure; imagesc(newsegvis); colormap(cmap_ov);
figure; imagesc(oldsegvis); colormap(cmap_orig); I’m trying to create a common colormap from two different categorical images that are segmentations of brain regions. The labels in "oldsegvis" are an entirely contained subset of the labels in "newsegvis". I’m expecting the same label value (e.g. newseg = 100, oldseg = 100) to return the same color, however, that is not the output behavior I’m observing. I’ve confirmed by looking at the values in the output newsegvis and oldsegvis arrays and by using "Data Tips" that the same values are being assigned different colors. Additionally, in the visualization of the "newsegvis" array, different values are being assigned the same color, which I’ve also confirmed with "Data Tips", even though the number of colors and the number of unique label values are the same. A code snippet is pasted below; I’m sure there’s something simple I’m missing, but would be very appreciative if someone could point it out to me. Thanks!
%% Visualize segmentations
%select section (transverse plane)
newsegvis = squeeze(newvol(:,:,100));
oldsegvis = squeeze(oldvol(:,:,100));
%set colormaps (new segmentations have all old segmentation labels plus
%additional labels)
newsegs = unique(newsegvis);
oldsegs = unique(oldsegvis);
cmap_ov = [0 0 0;rand(length(newsegs)-1,3)];
cmap_orig = cmap_ov(1:length(oldsegs),:);
%visualize segmentations
figure; imagesc(newsegvis); colormap(cmap_ov);
figure; imagesc(oldsegvis); colormap(cmap_orig); colormap, imagesc MATLAB Answers — New Questions