Determining Manual ROI from a graph (not image)

1 ビュー (過去 30 日間)
Jessi Martin
Jessi Martin 2022 年 11 月 28 日
編集済み: DGM 2022 年 11 月 29 日
Hi Everyone,
I'm writing a matlab script to analyze some gait data I have. I currently have a graph that shows 5 distinct steps (below). I need to partition each step out to analyze separately, i.e. break it into 5 different variables.
I know in image processing there is a way to allow the user to input a region of interest to allow for further processing. My question is that is there a way to do this for non-images like graphs? If so, what would be the function to do this?
Thanks!
Jessi M.

採用された回答

Image Analyst
Image Analyst 2022 年 11 月 28 日
Sure, just use drawrectangle to drag out a box that defines the region you want to include.
% Demo to show how drawrectangle can be used to draw a rectangular box on the image, and crop out that rectangular region to a new image.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
y = rand(1, 50);
hFig = figure;
plot(y, 'b-');
hFig.WindowState = 'maximized';
% Ask user to draw rectangle.
button = 'Redraw';
while contains(button, 'Redraw', 'IgnoreCase',true)
uiwait(helpdlg('Draw a box'));
% User draws a box. It exits as soon as they lift the mouse.
hBox = drawrectangle('Color', 'r');
% Get the coordinates in the form [xLeft, yTop, width, height].
roiPosition = hBox.Position;
% Delete the ROI object.
delete(hBox);
% and replace it with a rectangle in the graphical overlay.
hold on;
hRect = rectangle('Position', roiPosition, 'EdgeColor', 'r', 'LineWidth', 2);
% Ask user if the rectangle is acceptable.
message = sprintf('Is this good?');
button = questdlg(message, message, 'Accept', 'Redraw', 'Reject and Quit', 'Accept');
if contains(button, 'Quit','IgnoreCase',true)
delete(hRect); % Delete the box from the overlay.
roiPosition = [];
break;
elseif contains(button, 'Redraw','IgnoreCase',true)
% OPTIONAL If you want to delete the prior one before drawing the next one.
delete(hRect);
elseif contains(button, 'Accept','IgnoreCase',true)
break;
end
end
% If you want to delete the rectangle from the overlay, do this:
delete(hRect); % Delete the box from the overlay.
% Show roiPosition in command window
roiPosition
xLeft = roiPosition(1)
yTop = roiPosition(2)
xRight = xLeft + roiPosition(3)
yBottom = yTop + roiPosition(4)
% Draw lines
xline(xLeft, 'Color', 'r', 'LineWidth', 2);
xline(xRight, 'Color', 'r', 'LineWidth', 2);
yline(yTop, 'Color', 'r', 'LineWidth', 2);
yline(yBottom, 'Color', 'r', 'LineWidth', 2);
caption = sprintf('xLeft = %.2f, xRight = %.2f. yTop = %.2f, yBottom = %.2f', xLeft, xRight, yTop, yBottom);
title(caption, 'fontSize', fontSize)
If you want to turn the coordinates into indexes, you can use find() to find out which index is closest to the one you want. For example if you have x and y vectors
x1Index = find(x > xLeft, 1, 'first');
x2Index = find(x < xRight, 1, 'last');

その他の回答 (1 件)

DGM
DGM 2022 年 11 月 29 日
編集済み: DGM 2022 年 11 月 29 日

タグ

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by