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

2 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Image Analyst
Image Analyst le 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?

Plus de réponses (1)

bidisha
bidisha le 2 Mar 2013
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