Code covered by the BSD License  

Highlights from
Mouse figure interaction

image thumbnail

Mouse figure interaction

by

 

This example shows how the mouse could be used to change how an image is displayed

mouseMove ()
function mouseMove ()
    persistent imMax imMin imRange;
    % persistent imMin imMax;
    if isempty(imMin)
        clim = get(get(gcf, 'Children'), 'CLim');
        imMax = clim(2);
        imMin = clim(1);
        imRange = imMax - imMin;
    end
    point = get (gca, 'CurrentPoint');
    xLim = get (gca, 'XLim');
    yLim = get (gca, 'YLim');

    width = xLim(2) - xLim(1);
    height = xLim(2) - xLim(1);

    xPos = min(1, max(0, (point(1, 1) - xLim(1)) / (width))); % normed x - Range between 0 and 1;
    yPos = min(1, max(0, (point(1, 2) - yLim(1)) / (height))) ; % normed y - Range between 0 and 1;


    lowerBoundary = min(imRange - 1, max(0, xPos * imRange)); % value between 0 and imRange - 1
    uppderBoundary = min(imRange, max(lowerBoundary + 1, max(1, yPos * imRange))); % value between lowerBoundry + 1 and imRange

    range = [lowerBoundary, uppderBoundary];
    
    % display range
    title(gca, ['range = [', num2str(range(1)), ', ',num2str(range(2)), ']']);
    
    % set set dynamic range
    set(get(gcf, 'Children'), 'CLim', range);


end

Contact us