Why I can,t able to use parfor ?-Error: The variable options in a parfor cannot be classified.

1 view (last 30 days)
I am using parfor since my code takes too much time to compute the features, I here attach the code that i used
parfor no=1:49
% no=num_Frames(nx);
FEAT=[];
Org_class=[];
Ids=[];
% if sum(ismember(GT_ID,no))
% continue;
% end
fstr=['D:\My Work\Main Project\OCT\Denoised_cyst\spectralis_',num2str(mac_id),'\bscan_',num2str(no),'.jpg'];
%fstr=['F:\Anima\M Tech pgm\Main project\OCT cyst segmentation\OCT\Denoised_cyst\spectralis_',num2str(mac_id),'\bscan_',num2str(no),'.jpg'];
% warning('off');
rows=find(file(:,3)==no);
index=[];
for i=1:size(rows,1)
index(i,1)=file(rows(i),1);
index(i,2)=file(rows(i),2);
end
img=imread(fstr);
H = size(img,1);
W = size(img,2);
ibgt1=img;
% ROI restriction removing detected cysts below and above RPE & NFL
%file orders
idx=find(xid1==no);
%%creating GT image
grader_M=false(H,W);
for Row=1:size(index,1)
grader_M(index(Row,1), index(Row,2)) = true;
end
%%Preprocessing
%%Intensity Normalization
originalMinValue = double(min(min(img)));
originalMaxValue = double(max(max(img)));
originalRange = originalMaxValue - originalMinValue;
% Get a double image in the range 0 to +255
desiredMinVal = 0;
desiredMaxVal = 255;
desiredRange = desiredMaxVal - desiredMinVal;
dblImageS255 = desiredRange * (double(img) - originalMinValue) /(originalRange + desiredMinVal);
% Get a double image in the range 0 to +1
desiredMinVal = 0;
desiredMaxVal = 1;
desiredRange = desiredMaxVal - desiredMinVal;
I_norm = desiredRange * (double(img) - originalMinValue) /(originalRange + desiredMinVal);
%I_Smooth=imgaussfilt(I_norm);
Mask=fspecial('gaussian',[5 5]);
I_Smooth=imfilter(I_norm,Mask,'symmetric');
%%Feature Vector Calculation
I1=I_Smooth;
D=strel('Disk',5);
%I2=mmclose(I_Smooth,mmsedisk(5));
I2=imclose(I_Smooth,D);
Mask3=fspecial('gaussian',[5 5],2);
I3=imfilter(I_norm,Mask3,'symmetric');
Mask4=fspecial('gaussian',[5 5],4);
I4=imfilter(I_norm,Mask4,'symmetric');
Mask5=fspecial('gaussian',[5 5],6);
I5=imfilter(I_norm,Mask5,'symmetric');
Mask6=fspecial('gaussian',[5 5],8);
I6=imfilter(I_norm,Mask6,'symmetric');
Mask7=fspecial('gaussian',[5 5],10);
I7=imfilter(I_norm,Mask7,'symmetric');
Mask8=fspecial('gaussian',[5 5],12);
I8=imfilter(I_norm,Mask8,'symmetric');
Mask9=fspecial('gaussian',[5 5],14);
I9=imfilter(I_norm,Mask9,'symmetric');
Mask10=fspecial('gaussian',[5 5],16);
I10=imfilter(I_norm,Mask10,'symmetric');
Mask11=fspecial('gaussian',[5 5],18);
I11=imfilter(I_norm,Mask11,'symmetric');
h1=fspecial('laplacian',1);
I12=imfilter(I_norm,h1);
h2=fspecial('log',[3 3],2);
I13=imfilter(I_norm,h2);
sz=1; %sz>=2 MBLBP
I_p1 = padarray(I_Smooth, [sz sz], 'replicate');
[Ny , Nx] = size(I_p1);
N = 8;
scale = sz*[1 ; 1 ];
options.F = mblbp_featlist(Ny , Nx , scale);
options.map = uint8(0:2^N-1);
z1 = mblbp(I_p1 , options);
template = options.F(: , 1);
Nxx = (Nx-3*template(4) + 1);
Nyy = (Ny-3*template(5) + 1);
Imblbp1 = reshape(z1 , Nyy , Nxx);
sz1=2; %sz>=2 MBLBP
I_p2 = padarray(I_Smooth, [sz1 sz1], 'replicate');
[Ny1 , Nx1] = size(I_p2);
N1 = 8;
scale1 = sz1*[1 ; 1 ];
options.F = mblbp_featlist(Ny1 , Nx1 , scale1);
options.map = uint8(0:2^N-1);
z12 = mblbp(I_p2 , options);
template1 = options.F(: , 1);
Nxx1 = (Nx1-3*template1(4) + 1);
Nyy1 = (Ny1-3*template1(5) + 1);
Imblbp12 = reshape(z12 , Nyy1 , Nxx1);
sz2=3; %sz>=2 MBLBP
I_p3 = padarray(img, [sz2 sz2], 'replicate');
[Ny2 , Nx2] = size(I_p3);
N2 = 8;
scale2 = sz2*[1 ; 1 ];
options.F = mblbp_featlist(Ny2 , Nx2 , scale2);
options.map = uint8(0:2^N2-1);
z13 = mblbp(I_p3 , options);
template2 = options.F(: , 1);
Nxx2 = (Nx2-3*template2(4) + 1);
Nyy2 = (Ny2-3*template2(5) + 1);
Imblbp13 = reshape(z13 , Nyy2 , Nxx2);
sz3=4; %sz>=2 MBLBP
I_p4 = padarray(I_Smooth, [sz3 sz3], 'replicate');
[Ny3 , Nx3] = size(I_p4);
N3 = 8;
scale3 = sz3*[1 ; 1 ];
options.F = mblbp_featlist(Ny3 , Nx3 , scale3);
options.map = uint8(0:2^N3-1);
z14 = mblbp(I_p4 , options);
template3 = options.F(: , 1);
Nxx3 = (Nx3-3*template3(4) + 1);
Nyy3 = (Ny3-3*template3(5) + 1);
Imblbp14 = reshape(z14 , Nyy3 , Nxx3);
%%Test data Generation
[X Y]=size(I_Smooth);
for inx=10:W-10
for i=x2(inx,idx):x3(inx,idx) %NFL to RPE
% for inx=2:X-10
% for i=2:Y-10
win=I_Smooth(i-1:i+1,inx-1:inx+1);
I_ta=win;
Contrast1=[];
Homog1=[];
Energy1=[];
Corr1=[];
glcms1=graycomatrix(win,'Offset',[-1 -1;0 0; 0 -1; -1 1]);
stats1=graycoprops(glcms1);
Contrast1=[Contrast1;stats1.Contrast];
Homog1=[Homog1;stats1.Homogeneity];
Energy1=[Energy1;stats1.Energy];
Corr1=[Corr1;stats1.Correlation];
I1=double(I1);
I2=double(I2);
I3=double(I3);
I4=double(I4);
I5=double(I5);
I6=double(I6);
I7=double(I7);
I8=double(I8);
I9=double(I9);
I10=double(I10);
I11=double(I11);
I12=double(I12);
I13=double(I13);
Imblbp1=double(Imblbp1);
Imblbp12=double(Imblbp12);
Imblbp13=double(Imblbp13);
Imblbp14=double(Imblbp14);
Contrast1=double(Contrast1);
Homog1=double( Homog1);
Energy1=double( Energy1);
Corr1=double( Corr1);
if grader_M(i,inx)==1
FEAT=[ FEAT;I1(i,inx), I2(i,inx),I3(i,inx),I4(i,inx),I5(i,inx),I6(i,inx),I7(i,inx),I8(i,inx),I9(i,inx),I10(i,inx),I11(i,inx),I12(i,inx),I13(i,inx),Imblbp1(i,inx),Imblbp12(i,inx),Imblbp13(i,inx),Imblbp14(i,inx),Contrast1, Homog1,Energy1,Corr1];
Ids=[Ids;mac_id,no,i,inx];
Org_class=[Org_class;1];
else
FEAT=[ FEAT;I1(i,inx), I2(i,inx),I3(i,inx),I4(i,inx),I5(i,inx),I6(i,inx),I7(i,inx),I8(i,inx),I9(i,inx),I10(i,inx),I11(i,inx),I12(i,inx),I13(i,inx),Imblbp1(i,inx),Imblbp12(i,inx),Imblbp13(i,inx),Imblbp14(i,inx),Contrast1, Homog1,Energy1,Corr1];
Ids=[Ids;mac_id,no,i,inx];
Org_class=[Org_class;0];
end
end
end

Answers (1)

Walter Roberson
Walter Roberson on 18 Mar 2016
Did you define "options" before the parfor? If you did then parfor is going to see the code as trying to update "options". Any temporary variable of the computation should not be initialized before the "parfor" loop.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!