1

What I need to do is predefine a lot of ROI within MATLAB using imfreehand and then put these ROIs into a script. This really isn't that hard as I can name them and just keep drawing. But the thing I'm lost on is how to save these ROIs within a script without having to redefine the ROIS.

Basically how do I save an ROI in a script?

chappjc
  • 30,359
  • 6
  • 75
  • 132
Gbru
  • 97
  • 1
  • 8

2 Answers2

0

First, you can access the x,y coordinates of any lines you draw. When you call imfreehand, save its handle and use it to access the x,y data in the lines you drew.

hf = imfreehand;
% draw line, maybe insert pause here
hl = findobj(hf,'Type','line','Tag','top line');
x = get(hl,'XData');
y = get(hl,'YData');

Then you can use `mat2str2 to save the variables as strings that you can put into a script:

>> x = 1:10;
>> sprintf('x = %s',mat2str(x))
ans =
x = [1 2 3 4 5 6 7 8 9 10]

Just copy that into your script.

chappjc
  • 30,359
  • 6
  • 75
  • 132
  • That lets me take out the x and y data, but is there an easy way to put this into a script file? I don't want to have the imfreehand in the script as I don't want to have to draw 50 ROI's every time the program is run. This explain it a bit better? – Gbru Sep 29 '13 at 21:45
0

From MATLAB's documentation:

figure, imshow('pout.tif');
h = imfreehand;
position = wait(h); %This blocks until finished

you can also do

pos = getPosition(h) %gets the position

I think you are asking though about how to store each set of positions in one variable. For this a cell array is probably the most convenient thing. I hope that helps.

user2816823
  • 368
  • 5
  • 11