How can i use parfor in my code?

4 views (last 30 days)
John Smith
John Smith on 2 Mar 2018
Commented: Walter Roberson on 2 Mar 2018
I get an error saying "The variable rgb in a parfor cannot be classified." when i use "parfor" instead of for
here is my code
for m=1:size(rgb,1)
for n= 1:size(rgb,2)
for mm=1:size(t1rgb,1)
for nn= 1:size(t1rgb,2)
if abs(rgb(m,n,1)-t1rgb(mm,nn,1))<2 & abs(rgb(m,n,2)-t1rgb(mm,nn,2))<2 & abs(rgb(m,n,3)-t1rgb(mm,nn,3))<2
gray = .3*rgb(m,n,1)+.59*rgb(m,n,2)+.11*rgb(m,n,3);
rgb(m,n,:)= [gray gray gray];
end
end
end
end
end
  1 Comment
Walter Roberson
Walter Roberson on 2 Mar 2018
I really recommend that you vectorize your code.
Do I understand correctly that for each given pixel location, if the pixel is within (+/-2, +/-2, +/-2) for any pixel in t1rgb, that you want to replace the rgb pixel with a gray scale version of itself ?? If so then you could vectorize the test by using ismembertol() with an absolute tolerance configured.

Sign in to comment.

Answers (0)

Categories

Find more on Deep Learning Toolbox 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!