Generating multiple ROIs from a single image. (Automatic generation of ROI required)
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
Accepted Answer
More Answers (1)
bidisha
on 2 Mar 2013
0 votes
Categories
Find more on Big Data Processing 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!