简体   繁体   中英

Change image colormap to deuteranopia in Matlab

I've been trying for a long time to change my colormap of my images using a custom 256x3 colormap to switch the impression of a 'normal sighted' person to the one a person with deuteranopia (red-green-blindness) can see.

The colormap has already been created, but in no way I get to apply it to the original image.

The code

load('ColormapsDefVis.mat')

fig=figure
a=imread('Regenbogen.png');

[b map]=rgb2ind(a,256);

c=ind2rgb(b, DeuteranopiaColorMap);
imshow(c);

did not work as well as

load('ColormapsDefVis.mat')
fig=figure
a=imread('Regenbogen.png');

imshow(a);

set(fig,'Colormap',DeuteranopiaColorMap)

did not.

Does anyone know how to change the custom colormap correctly?

I would appreciate your help very much!

The first peice of code works. You have to be making a mistake or interpreting the results wrongly.

I suggest you look a to a thing. Make sure you image is unit8 or single . Additionally, you probably dont what dithering to happen, so I suggest you do rgb2ind(a,256, 'nodither') . The results of the dithering may be fooling your eyes, but we can't know as you didn't post any image.

To convince yourself that rgb2ind works, see the code below. You should be able to test it in you computer.

img=imread('cameraman.tif');
indimg=img;
cmap=hsv(255); % colromap 1
cmap2=cmap(end:-1:1,:);  % colromap 2
subplot(121);
c=ind2rgb(indimg,cmap );
imshow(c)
subplot(122);
c2=ind2rgb(indimg,cmap2 );
imshow(c2)

在此处输入图片说明

Thank you very much for your help Ander, the approach using colormaps was just not the efficient solution i was looking for. Although I am sure it would work too, there is a way easier solution for the problem :)

To receive the impression of being red-green-blind I took the idea that people suffering from this condition cannot distinguish between reddish and greenish objects. So my solution is to plot the mean from the red and green RGB-image channel in both channels to make them indistinguishable.

a=imread('peppers.png');
figure,
subplot(121)
imshow(a)
c=(a(:,:,1)+a(:,:,2))/2; %Mean value between channel red and green
a(:,:,1)=c; %Switch the red channel to the mean
a(:,:,2)=c; %Switch the green channel to the mean
subplot(122)
imshow(a)

Unfortunately, stackoverflow refuses me to upload images as I do not have enough reputation, but the code shall work using any RGB-image, for example the builtin demo image 'peppers.png'.

Hope this helps anyone else too!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM