Matlab 中沿直线段的像素强度值

Pixel intensity values along imline segment in Matlab

考虑使用一些通用描述的 Matlab imagesc() 轴显示的图像,比如 10x10 像素,其中每个像素的强度值在 [0 255 ].

使用图像分析工具包中的 imline() 方法,我想沿着用户交互定义的一条线检索像素强度值。俗称"line profile"。这里的重要区别在于平行于 X 或 Y 轴的线是不够的。该线必须由用户交互式绘制。

到目前为止我已经研究了 Matlab 方法 improfile()impixel() 但到目前为止我还没有设法得到期望的结果。

这是一段代码,它读取图像 (objectHandle) 被点击的位置并更新行 (currentLine 句柄) 值和文本框中的字符串 (Coords 句柄) .

%% Code here
axis tight
imageHandle = imshow('input\foo.jpg');
set(imageHandle,'ButtonDownFcn',{@ImageClickCallback,Coords,currentLine});
%% Code there

function ImageClickCallback (objectHandle,~,Coords,currentLine)
axesHandle  = get(objectHandle,'Parent');
coordinates = get(axesHandle,'CurrentPoint');   %// This line reads the click
coordinates = coordinates(1,1:2);
LineX=get(currentLine,'xdata');
LineY=get(currentLine,'ydata');
set(currentLine,'xdata',[LineX,coordinates(1)])
set(currentLine,'ydata',[LineY,coordinates(2)])

set(Coords.X,'string',{'X';num2str(coordinates(1),'%.0f')})
set(Coords.Y,'string',{'Y';num2str(coordinates(2),'%.0f')})

end