Generating multiple ROIs from a single image. (Automatic generation of ROI required)
4 views (last 30 days)
Show older comments
I have this code below which works fine, but it is time consuming.
Is there a better and faster solution possible?
if true im = imread('my_image.png'); I = single(rgb2gray(im))/255;
%getting height and width of image
width = size(im,2);
height = size(im,1);
k = 15;
x = randsample(height,k);
y = randsample(width,k);
sP = horzcat(x,y);
for i = 1:k
if (((sP(i,1)+100) < height) && ((sP(i,2)+100) < width) && ((sP(i,1)-100) > 0) && ((sP(i,2)-100) > 0))
x_min = sP(i,1)-100;
x_max =sP(i,1) + 100;
y_min = sP(i,2)-100;
y_max = sP(i,2)+100;
roi = im(x_min:x_max,y_min:y_max,:);
imwrite(roi,['MYlocation' strcat(num2str(i) ,'_roi.png')],'png');
elseif((((sP(i,1)+200) < height) || ((sP(i,1)- 200) > 0)) && (((sP(i,2)+200) < width) || ((sP(i,2)- 200) > 0)))
if ((sP(i,1)+200) < height)
x_min = sP(i,1);
x_max = (sP(i,1)+200);
elseif ((sP(i,1)- 200) > 0)
x_min = sP(i,1)-200;
x_max = sP(i,1);
end
if((sP(i,2)+200) < width)
y_min = sP(i,2);
y_max = (sP(i,2)+200);
else
y_min = (sP(i,2)- 200);
y_max = sP(i,2);
end
roi = im(x_min:x_max,y_min:y_max,:);
imwrite(roi,['MYlocation' strcat(num2str(i) ,'_roi.png')],'png');
else
continue;
end
end
end
0 Comments
Accepted Answer
Image Analyst
on 1 Mar 2013
It's not time consuming on my computer - it's pretty fast.
Elapsed time is 0.675276 seconds.
And that even included an imshow() to see what I was saving. How long does it take for you?
0 Comments
More Answers (1)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!