Borrar filtros
Borrar filtros

Setting common color maps for categorical images with no ordinal information in the categorical labels

8 visualizaciones (últimos 30 días)
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);

Respuestas (1)

Christopher Mezias
Christopher Mezias el 22 de Abr. de 2024
Movida: Cris LaPierre el 8 de Mayo de 2024
I figured out a solution:
Use changem or another similar function to replace the segmentation labels with ordinal labels from 0 (empty label) to length(unique(labels)). I implemented the approach as given in the below code snippet, and got appropriate output. I'll leave the question up in case anyone has a different and more elegant solution for future users.
newsegvis = squeeze(newvol(:,:,100));
oldsegvis = squeeze(oldvol(:,:,100));
newsegs = unique(newsegvis);
oldsegs = unique(oldsegvis);
newsegvis = changem(newsegvis,(0:length(newsegs)-1)',newsegs);
oldsegvis = changem(oldsegvis,(0:length(oldsegs)-1)',oldsegs);
  1 comentario
Cris LaPierre
Cris LaPierre el 22 de Abr. de 2024
Movida: Cris LaPierre el 8 de Mayo de 2024
Here's another suggestion that lets you use the same colormap in both images and doesn't require changing your labels.
newsegs = unique(newsegvis);
oldsegs = unique(oldsegvis);
cmap = [0 0 0;rand(length(newsegs)-1,3)];
%visualize segmentations
figure; imagesc(newsegvis); colormap(cmap); clim([0 max(newsegs)])
figure; imagesc(oldsegvis); colormap(cmap); clim([0 max(newsegs)])
The Medical Imaging Toolbox defines the label definitions in a table. You can extract the label colors to create your colormap.
cmap = [0 0 0; gTruthMed.LabelDefinitions.LabelColor];

Iniciar sesión para comentar.

Categorías

Más información sobre Colormaps en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by