Question about the cut of the score of MATLAB?

I have a section of code that finds Harris angles in a sequence of images. I need to do this for 92 images, but it's pretty slow. So, I would like to run the code in parallel. The code below has an error related to the variable "angles"

%% Harris corners max_pts = 900; corners = zeros(max_pts,2,size(images,3)); parfor i = 1:size(images,3) I = images(:,:,i); [yx] = get_corners(I,max_pts); corners(1:length(y),:,i) = [yx]; end 

What says:

MATLAB starts loops in parfor functions by dividing iterations of the loop into groups and then sending them to MATLAB working groups, where they work in parallel. In order for MATLAB to do this in a repeatable, reliable way, it must be able to classify all the variables used in the loop. The code uses the specified variable in a way that is incompatible with classification. Suggested action Correct the use of the specified variable. For more information about classifying variables and other restrictions on iterating a pair cycle, see the "Classification of Variables" section of the Parallel Computing Toolbox documentation.

Any ideas how to fix this?

Thanks!

+7
source share
2 answers

As @Chris mentioned, line

 corners(1:length(y),:,i) = [yx]; 

- a problem. An easy way to make sure that corners are truncated is to use an array of cells

 max_pts = 900; cornerCell = cell(size(images,3),1); parfor i = 1:size(images,3) I = images(:,:,i); [yx] = get_corners(I,max_pts); cornerCell{i} = [yx]; end 

If you do not want the angles to be an array of cells (note that to build angles for the i-th image you can call imshow(images(:,:,i),[]),hold on, plot(cornerCell{i}(:,1),cornerCell{i}(:,2),'o') ), you can always convert back to the source file 900-by-2, nImages array in a loop that won't cost you any noticeable time:

 corners = zeros(max_pts,2,size(images,3)); for i=1:size(images,3) corners(1:size(cornerCell{i},1),:,i) = cornerCell{i}; end 
+7
source

First of all:

  corners(1:length(y),:,i) = [yx]; 

This is problem.

Have you read the documentation?

http://www.mathworks.com/help/toolbox/distcomp/brdqtjj-1.html#bq_tcng-1

The shape of the array. When assigning a sparse variable, the right-hand side of the assignment is not [] or '' (these operators indicate the removal of elements).

The shape of the array. The intersected variable must be in constant form. The variable A shown here on any line is not chopped:

A (i, :) = []; A (end + 1) = i;

Reason A is not cut in any case, since changing the shape of the cut array will violate the assumptions governing the relationship between the client and the workers.

I'm not very good at what x and y are, but now it should be clear what the problem is. Can you rewrite this so that you do not assign [] to the slice?

+2
source

All Articles