开发者

Matlab - attach scalar value to RGB colours

When I read the following image into Matlab I am obtaining a 3D matrix which basically contains the values of RGB colour samples which compose every pixel within the image.

Matlab - attach scalar value to RGB colours

Is there any Matlab function which I can use to assign a scalar value between lets say [-10, 10] to every pixel within the image based on the RGB values? Pure red should be like 10, yellow should开发者_如何学Python be 5, green should be 0, blue should be like -8 and cyan should be like -10.


Have a look at RGB2IND: http://www.mathworks.com/help/techdoc/ref/rgb2ind.html

You could then replace the Nx3 index output with your own custom N element index vector.


As you can see from running

colorlist=[1 0 0;1 1 0;0 1 0; 0 0 1; 0 1 1];
valuelist=[10 5 0 -8 -10];
figure;
hold all;
for i=1:10
  bar(i,i,'FaceColor',colorlist(i,:))
end;

the colorlist defined above corresponds to the colors you are interested in.

To solve your question, for each pixel in your image, you would have to determine which RGB values are exactly zero and which ones are exactly one to determine between which pair you want to interpolate. For example, assuming size(image)==[100,100,3] and image=im2double(imread(myfilename)) i.e. max(image(:))==1:

if ((image(x,y,:)==0)==[0 0 1]) && ((image(x,y,:)==1)==[1 0 0])
    %# interpolate between red and yellow
    result(x,y)=10 - 5*image(x,y,2); %# pure red gives 10, pure yellow gives 5
elseif ((image(x,y,:)==0)==[0 0 1]) && ((image(x,y,:)==1)==[0 1 0])
    %# interpolate between yellow and green
    result(x,y)=5*image(x,y,1); %# pure yellow gives 5, pure green gives 0
elseif 
    %# ...
end

This solution is not vectorized, but it should get you on the right track for a doable implementation. Of course, if you could avoid saving the data with a multicolor lookup-table as RGB but save the raw values instead, you could save yourself some hassle...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜