Reputation: 1
I have a double matrix in matlab and I want to convert it to an HSV image where supposedly similar double values will appear with same color. I already converted to RGB with mat2gray but I want to to convert directly from double matrix to hsv image. Is it possible?
Thanks
Upvotes: 0
Views: 995
Reputation: 12693
You're asking if you can do what image
and imagesc
do. Yes, you can. You just need to interpolate into the 'hsv' colormap. The following code snippet demonstrates how to do this. It assumes your values are scaled between 0 and 1; you can easily change that though.
im = [0 .5 1; .7 .6 .2; .9 .3 .4];
cm = colormap('hsv');
cdata = interp1(linspace(0,1,length(cm)),cm,im);
figure;image(cdata)
cdata
will be a (row x col x 3) matrix, you can use image
directly to see it, or do whatever else you need to from there.
Upvotes: 2