0
votes

Consider an image displayed using Matlab imagesc() axes of some generic description, say 10x10 pixels, where each pixel has an intensity value in [0 255].

Using the imline() method in the image analysis toolkit I would like to retrieve the pixel intensity values along a line defined interactively by the user. Commonly known as a "line profile". The important difference here is that a line parallel to either X or Y axis is insufficient. The line has to be interactively drawn by the user.

So far I have looked into Matlab methods improfile() and impixel() but so far I have not managed to get the desired result.

1
improfile does exactly this. Where are you running into difficulty?Peter
Maube with the interactive input. In that case look for callback actions for axes .Crowley
@Crowley Callbacks for axes solved all my problems. Thank you. If you want me to up vote your suggestion post it as a solution.Peter

1 Answers

0
votes

This is a piece of code that reads where the image (objectHandle) is clicked and updates the line (currentLine handle) value and string in textboxes (Coords handle).

%% 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