How to recostruct ROI on an image and diaplay it?

1 回表示 (過去 30 日間)
Pramod Bhat
Pramod Bhat 2011 年 10 月 20 日
dear friends, I hav got a set of co ordinates of an ROI. Now i want to reconstruct the ROI on an image and display it. How can i do this? plz help....
  1 件のコメント
Jonas Reber
Jonas Reber 2011 年 10 月 20 日
of what kind are these coordinates? is it a list of all pixels in the ROI or is it the marker/vertices of a boundary polygon (e.g., 4 points for a rectangle) or else?

サインインしてコメントする。

回答 (3 件)

Jonas Reber
Jonas Reber 2011 年 10 月 20 日
after having read your first question ( http://www.mathworks.com/matlabcentral/answers/18789-how-to-save-an-image-displayed) I think I understand what you try to accomplish. Since you are using imfreehand, I assume you have Image Processing Toolbox.
I have written an example code that opens an image, lets you select a ROI and saves it to a new file with transparent background. have a look at it - you should now be able to do what you are looking for:
%%example code for Pramod Bhat from Jonas:
% get file to be displayed
[FileName,PathName] = uigetfile('*.*','Select the Image');
[img, map] = imread(fullfile(PathName,FileName));
% display image and select region
f = figure;
imshow(img, map);
roi = imfreehand(gca);
wait(roi);
% get the mask
mask = roi.createMask;
% extract the boundarybox of the ROI
S = regionprops(mask,'Boundingbox');
b = floor(S(1).BoundingBox);
% crop the interesting part of the image (bounding box)
imgcut = img(b(2):b(2)+b(4), b(1):b(1)+b(3));
maskcut = double(mask(b(2):b(2)+b(4), b(1):b(1)+b(3)));
% finally, save the image
[FileName,PathName] = uiputfile('*.png','Save the Image As');
imgcutrgb = ind2rgb(imgcut,map);
% note: only what is inside of your ROI will be displayed,
% the rest is set to be transparent:
imwrite(imgcutrgb,fullfile(PathName,FileName),'Alpha', maskcut);

Mohammad
Mohammad 2012 年 12 月 24 日
編集済み: Mohammad 2012 年 12 月 24 日
hello there how can i exclude ROI and save only RONI which is whole image except selected ROI. plz help
  2 件のコメント
Walter Roberson
Walter Roberson 2012 年 12 月 24 日
extract ~ROI
Image Analyst
Image Analyst 2012 年 12 月 24 日
I don't see any such function as "extract". Where do you get it?

サインインしてコメントする。


Image Analyst
Image Analyst 2012 年 12 月 24 日
編集済み: Image Analyst 2012 年 12 月 24 日
See my BlobsDemo http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862. It finds coins in an image, finds the bounding box of each coin, and then extracts (crops) each bounding box to its own image.

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by