1

I'm trying to use parfor to estimate the time it takes over 96 sec and I've more than one image to treat but I got this error:

The variable B in a parfor cannot be classified

this the code I've written:

Io=im2double(imread('C:My path\0.1s.tif')); 
Io=double(Io);
In=Io;
sigma=[1.8 20];
[X,Y] = meshgrid(-3:3,-3:3);
G = exp(-(X.^2+Y.^2)/(2*1.8^2));
dim = size(In);
B = zeros(dim);
c = parcluster
  matlabpool(c)
parfor i = 1:dim(1)
    for  j = 1:dim(2)
         % Extract local region.
         iMin = max(i-3,1);
         iMax = min(i+3,dim(1));
         jMin = max(j-3,1);
         jMax = min(j+3,dim(2));
         I = In(iMin:iMax,jMin:jMax);
         % Compute Gaussian intensity weights.
         H = exp(-(I-In(i,j)).^2/(2*20^2));
         % Calculate bilateral filter response.
         F = H.*G((iMin:iMax)-i+3+1,(jMin:jMax)-j+3+1);
         B(i,j) = sum(F(:).*I(:))/sum(F(:));   
  end
   end
 matlabpool close

any Idea?

Cape Code
  • 3,584
  • 3
  • 24
  • 45
Ahmed
  • 321
  • 1
  • 3
  • 14

1 Answers1

2

Unfortunately, it's actually dim that is confusing MATLAB in this case. You can fix it by doing

[n, m] = size(In);
parfor i = 1:n
    for j = 1:m
        B(i, j) = ...
    end
end
Edric
  • 23,676
  • 2
  • 38
  • 40
  • Parfor can be significantly slower, a detailed discussion can be found here: http://stackoverflow.com/questions/3174358/matlab-parfor-is-slower-than-for-what-is-wrong In this case: Most of the operations you are using are already multi-threaded. The potential gain is low. – Daniel Feb 13 '14 at 22:36
  • Matlab parfor is very limited and stupid. A lot of stupid restrictions. I just hate it. The compiler is very bad programmed. – Pedro77 Jun 02 '16 at 14:39