Generating multiple ROIs from a single image. (Automatic generation of ROI required)

2 ビュー (過去 30 日間)
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

採用された回答

Image Analyst
Image Analyst 2013 年 3 月 1 日
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?

その他の回答 (1 件)

bidisha
bidisha 2013 年 3 月 2 日
Elapsed time is 5.131721 seconds. Right now I am doing it for an image of size 226 by 502. I might be using larger ROIs and hence generate more number of samples from it.

Community Treasure Hunt

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

Start Hunting!

Translated by