image processing with parallel computing gives incorrect results

1 visualización (últimos 30 días)
Maria Kanwal
Maria Kanwal el 12 de Nov. de 2016
Comentada: Ahmet Cecen el 13 de Nov. de 2016
i need to read all images in a folder in groups of 3 and process them for that i am using a broadcast variable to store the names of all the images, i want to do it by using parallel computing but results are different from the results i get by using simple for loop. Here is the example code, any suggestion how can i get correct results?
inDir ='./abc/';
Imgs = dir([inDir '*.jpg']);
parfor indx=2:length(Imgs)-1
im1=imread([inDir Imgs(indx-1).name]);
im2=imread([inDir Imgs(indx).name]);
im3=imread([inDir Imgs(indx+1).name]);
% resultimg=someprocessing using im1,im2 and im3
% write resultimg
end

Respuestas (2)

Ahmet Cecen
Ahmet Cecen el 12 de Nov. de 2016
I am not very knowledgeable with the implementation of ParFor, but I would wager a guess the problem is your indexing: specifically the presence of indx-1 and indx+1.
Try to see if creating three lists of images and indexing them all with indx fixes the problem. Something like:
Imgs = dir([inDir '*.jpg']);
ImgsBefore = circshift(Imgs,1);
ImgsAfter = circshift(Imgs,-1)
parfor indx=2:length(Imgs)-1
im1=imread([inDir ImgsBefore (indx).name]);
im2=imread([inDir Imgs(indx).name]);
im3=imread([inDir ImgsAfter (indx).name]);
% resultimg=someprocessing using im1,im2 and im3
% write resultimg
end
As I mentioned, this is simply a guess and might not work. Just come back and let it known if it doesn't.
  2 comentarios
Maria Kanwal
Maria Kanwal el 13 de Nov. de 2016
results are different than before but still do not match for loop results
Ahmet Cecen
Ahmet Cecen el 13 de Nov. de 2016
I have tried a basic operation of this form (a triple convolution) and I get consistent results with for and parfor. I have no idea what else can be the problem.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 13 de Nov. de 2016
inDir ='./abc/';
Imgs = dir( fullfile(inDir, '*.jpg') );
numimg = length(Imgs);
parfor indx = 1 : numimg
im{indx} = imread( fullfile(inDir, Imgs(indx).name) );
end
parfor indx=2:length(Imgs)-1
im1 = im{indx-1};
im2 = im{indx};
im3 = im{indx+1};
% resultimg=someprocessing using im1,im2 and im3
% write resultimg
end
If the result is not the same as before then it might have to do with the processing you are doing.
  3 comentarios
Walter Roberson
Walter Roberson el 13 de Nov. de 2016
I think the differences you are observing have to do with the processing you are doing (which you did not show us.)

Iniciar sesión para comentar.

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by