如何显示图像中特定像素的LA * B *值?

时间:2011-12-20 07:08:02

标签: matlab matlab-figure

之前有代码'pixval on'在图像的每个像素中显示rgb的值 现在已经过时了。
我想知道如何为LAB转换图像做同样的事情。

1 个答案:

答案 0 :(得分:1)

首先,创建一个带有图像的图形

function so1
   global im;
   im = imread('peppers.png');
   figure;imshow(im);    
 end

然后,创建一个新的数据光标,选择“选择文本更新功能” enter image description here

并选择以下回调文件:

function output_txt = NewCallback(obj,event_obj)
% Display the position of the data cursor
% obj          Currently not used (empty)
% event_obj    Handle to event object
% output_txt   Data cursor text string (string or cell array of strings).
global im;
pos = get(event_obj,'Position');
val = squeeze(im(pos(2),pos(1),:))';
srgb2lab = makecform('srgb2lab');
labVal = applycform(val,srgb2lab);
output_txt = sprintf('LAB = [%d,%d,%d]',labVal(1),labVal(2),labVal(3));

这里唯一的缺点是全局的丑陋使用,可能会被删除,但这不是问题。