How to edit ROI after already saved?
조회 수: 9 (최근 30일)
이전 댓글 표시
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
DGM
2023년 5월 25일
편집: DGM
2023년 5월 25일
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.
채택된 답변
Shubham
2023년 5월 31일
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.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!