6 views (last 30 days)

Hi, i want to display a plot of scanning track on the original image but the axes values of the image are different from the values of the plot graph (the image i got is attached, the plot is appears in RED color at the top left of the image and the dimensions of the plot is much smaller than the dimensions of the image). How can I make sync between the axes system of the image and the plot scanning track?

Thanks, Itai

Image Analyst
on 17 Jan 2016

Image Analyst
on 17 Jan 2016

Thorsten
on 19 Jan 2016

Edited: Thorsten
on 19 Jan 2016

x = cumsum(Volt_and_time(2,:));

y = cumsum(Volt_and_time(1,:));

overlayplot(x,y,image, 'fitbinary')

using my function overlayplot:

function h = overlayplot(x, y, I, rect)

%OVERLAYPLOT Plot an overlay of function x,y on the image I.

%

% H = OVERLAYPLOT(X, Y, I, [RECT])

%

% Plots that do not keep the aspect ratio of the plot:

% OVERLAYPLOT(X, Y, I) Plot function scaled to the size of the image I.

% OVERLAYPLOT(X, Y, I, RECT) Plot function scaled to rectangle. Rectangle

% is given by its coordinates [XMIN XMAX YMIN YMAX].

%

% Function scaled to the size of the image, keeping the aspect ratio of the

% plot:

% OVERLAYPLOT(X, Y, I, []) Plot function witout offset.

% OVERLAYPLOT(X, Y, I, DXY) Plot function with an offset in X and Y

% direction given by DXY = [DX DY].

% OVERLAYPLOT(X, Y, I, OPTION), with OPTION = 'center' or 'c'. Plot

% centered on the image.

% OVERLAYPLOT(X, Y, I, OPTION), with OPTION = 'fitbinary' or 'ft'. Plot

% fitted to the white area of the binary image I.

%

% Thorsten.Hansen@psychol.uni-giessen.de 2016-01-19

%%Process arguments

switch nargin

case 3

plotoption = 1;

case 4

if ischar(rect)

if strcmp(rect, 'center') || strcmp(rect, 'c')

plotoption = 33; % keep ratio, center

elseif strcmp(rect, 'fitbinary') || strcmp(rect, 'fb')

% fit to rectangle given by white area of binary image

if ~islogical(I)

error('Image must be of class logical for option fitbinary.')

end

rect = [find(diff(sum(I)>0)~= 0) find(diff(sum(I,2)'>0)~= 0)];

rect = rect + [1 0 1 0]; % correct off by one error

plotoption = 2;

else

error('String must be ''center'', ''c'', ''fitbinary'' or ''fb''.')

end

else

switch numel(rect)

case 0

plotoption = 31; % keep ratio, no offset

case 2

plotoption = 32; % keep ratio, offset dx, dy given in rect

case 4

plotoption = 2; % scale to fit given rectangle

otherwise

error('Wrong number of elements, must be 0, 2 or 4.')

end

end

otherwise

errro('Wrong number of arguments, must be 3 or 4.')

end

%%Determine scale factors and offset

% first scale xy to [0,1]

wxy = max(x) - min(x); hxy = max(y) - min(y);

x0 = (x - min(x))/wxy;

y0 = (y - min(y))/hxy;

wI = size(I,2); hI= size(I,1); % width and height of image

switch plotoption

case 1 % scale plot to full size of image, ignoring ratio of plot

sx = wI; sy = hI;

dx = 0; dy = 0; % no offset

case 2 % scale plot to fit rectangle rectxy

% rectangle given by [xmin, xmax, ymin, ymax]

xmin = rect(1); xmax = rect(2); ymin = rect(3); ymax = rect(4);

sx = xmax - xmin; sy = ymax - ymin;

dx = xmin;

dy = ymin;

case {31, 32, 33} % scale plot, keeping ratio

% determine ratio of image and plot and scale accordingly

rI = wI/hI; % width/height

rxy = wxy/hxy;

if rI > rxy

s = hI;

else

s = wI;

end

sx = s; sy = s;

% determine offset

switch plotoption

case 31 % empty rect

dx = 0; dy = 0; % default is no offset

case 32 % offset in x and y

dx = rect(1); dy = rect(2);

case 33 % center

dx = (wI-sy)/2;

dy = (hI-sx)/2;

otherwise

error('Internal error: plotoption can be only 31, 32, or 33.')

end

otherwise

error('Internal error, plotoption can only be 1, 2 or 3.');

end

%%Show overlay

imshow(I)

hold on

h = plot(sx*x0+dx, sy*y0+dy);

if nargout == 0, clear h, end

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.