image processing with parallel computing gives incorrect results

조회 수: 2 (최근 30일)
Maria Kanwal
Maria Kanwal 2016년 11월 12일
댓글: Ahmet Cecen 2016년 11월 13일
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

답변 (2개)

Ahmet Cecen
Ahmet Cecen 2016년 11월 12일
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
Maria Kanwal
Maria Kanwal 2016년 11월 13일
results are different than before but still do not match for loop results
Ahmet Cecen
Ahmet Cecen 2016년 11월 13일
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.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2016년 11월 13일
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
Walter Roberson
Walter Roberson 2016년 11월 13일
I think the differences you are observing have to do with the processing you are doing (which you did not show us.)
Maria Kanwal
Maria Kanwal 2016년 11월 13일
i'm computing optical flow ( optical flow )

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by