Clear Filters
Clear Filters

How to edit ROI after already saved?

9 views (last 30 days)
Jonah
Jonah on 25 May 2023
Commented: Jonah on 31 May 2023
I have a set of images, with ROIs already drawn on them using drawpolyline. I would like to now be able to open the images with the ROIs, and modiy them (ie. make them bigger/smaller, move them around). Is there any way to do this?
  1 Comment
DGM
DGM on 25 May 2023
Edited: DGM on 25 May 2023
How exactly did you "save" an ROI object on an image? Do you mean that you drew a white polygon on an image? If so, you might be able to get an approximation of the original polygon from the modified image, but you won't get the original image information back, so modifying the polygon in the edited image itself is not generally possible (unless you have the original image).
You'd have to provide an example of what you've done in order to know.

Sign in to comment.

Accepted Answer

Shubham
Shubham on 31 May 2023
Hi Jonah,
Yes, you can open images with ROIs and modify them in MATLAB using the imshow function and the imrect, imellipse, or imfreehand functions for selecting ROIs.
Here's some sample code to get you started:
% Load image
img = imread('path/to/image.jpg');
% Display image
imshow(img);
% Define ROI
roi = imrect;
% Alternatively, you can use imellipse or imfreehand to create different kinds of ROIs.
% Get ROI position
pos = getPosition(roi);
% Modify ROI position
pos(3) = pos(3) + 50; % Increase width of ROI by 50 pixels
pos(4) = pos(4) + 50; % Increase height of ROI by 50 pixels
pos(1) = pos(1) - 25; % Move ROI 25 pixels to the left
pos(2) = pos(2) - 25; % Move ROI 25 pixels up
% Update ROI
setPosition(roi, pos);
% Get image inside ROI
cropped_img = imcrop(img, pos);
% Display cropped image
imshow(cropped_img);
In this code, we first load an image and display it using the imshow function. We then define an ROI using the imrect function and modify its position. We can get the new position using getPosition and set it using setPosition. Finally, we extract the part of the image inside the ROI using imcrop and display it using imshow.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!