I am trying to segment an image of (512 x 512) into 4 segments of (128 x 128) images having the upper row of the orignal image. Then trying to run parallel parfor loop on it. But unable to do so. Here is my code.
FinalImage = ones(512,512);
%visiblity function initialization, see equation (4)
parfor imageSegment = 1:8;
img = double(imread([filename '.jpg']))./255;
img = im2bw(img);
if imageSegment == 1
img = img(1:128,1:128);
[nrow, ncol] = size(img);
elseif imageSegment == 2
img = img(1:128,129:256);
[nrow, ncol] = size(img);
elseif imageSegment == 3
img = img(1:128,257:384);
[nrow, ncol] = size(img);
elseif imageSegment == 4
img = img(1:128,385:512);
[nrow, ncol] = size(img);
for nMethod = 3:3;
//Some code
end
end
imwrite(FinalImage, gray(256), [filename '_FinalImage_' num2str(nMethod) '.bmp'], 'bmp');
fprintf('close');
How to use FinalImage variable inside the parfor loop ??
To extract all
16segments (of size128*128) of a512*512image in a parallel way, you may want to try the following code:The result would be
16images in the following order:I wrote the program in a parametric way i.e. you can input any image of
2^m*2^mand ask for any number of segmentsn = 2^qwheremandqare arbitrary numbers.The
imreadopening online images is slow, you may want to have your images on disk. Also, you can uncomment theparpoolto change the number of workers, if you're on a HPC cluster.