Retrieving Outputs From SPMD
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Jacob Mevorach
      
 el 30 de Mzo. de 2017
  
    
    
    
    
    Comentada: Jacob Mevorach
      
 el 5 de Abr. de 2017
            Here's the function I've been using without SPMD
function [mask] = bbox_analysis(bboxes, mask, blackwhiteframe, th, fractional_th)
    % Cycle through every bbox in the frame
    bbox_dim = size(bboxes);
    for b = 1:bbox_dim(1)
        x_1 = bboxes(b, 1);
        y_1 = bboxes(b, 2);
        x_2 = x_1 + bboxes(b, 3);
        y_2 = y_1 + bboxes(b, 4);
        cropped_image = imcrop(blackwhiteframe, [x_1, y_1, bboxes(b, 3), bboxes(b, 4)]);      % Section of frame captured in bbox
        max_image = max(cropped_image);
        threshold = max(th/255, max_image*fractional_th);
        new_image = (cropped_image > threshold);
        for i = x_1:x_2-1
            for j = y_1:y_2-1
                mask(j, i) = new_image(j+1-y_1, i+1-x_1);
            end
        end
    end
I've implemented SPMD in the following manner.
  function [mask] = bbox_analysis(bboxes, mask, blackwhiteframe, th, fractional_th)
    % Cycle through every bbox in the frame
    spmd(0,6)
    bbox_dim = size(bboxes);
    for b = labindex:numlabs:bbox_dim(1)
        x_1 = bboxes(b, 1);
        y_1 = bboxes(b, 2);
        x_2 = x_1 + bboxes(b, 3);
        y_2 = y_1 + bboxes(b, 4);
        cropped_image = imcrop(blackwhiteframe, [x_1, y_1, bboxes(b, 3), bboxes(b, 4)]);      % Section of frame captured in bbox
        max_image = max(cropped_image);
        threshold = max(th/255, max_image*fractional_th);
        new_image = (cropped_image > threshold);
        for i = x_1:x_2-1
            for j = y_1:y_2-1
                mask(j, i) = new_image(j+1-y_1, i+1-x_1);
            end
        end
    end
    end 
end
But now mask is returned as a composite variable and I would like to return in to the state it was originally being outputted. I've been having trouble understanding how to process the composite variable back into the original form it was being outputted in before I implemented SPMD. Does anyone know how I might be able to process the composite variable to cause it to return to the same form it existed in before? I would greatly appreciate any help in this regard.
0 comentarios
Respuesta aceptada
  Sharmila Raghu
    
 el 3 de Abr. de 2017
        In order to gather the individual components of the composite variable into a single array in the MATLAB base workspace, the following modifications must be done to the code:
1) The composite variable should be indexed starting from 1 on every lab. This is because every lab has its own local copy of the variable. Those labs do not know anything about where their work belongs in the whole array, so construct each individual array without taking indexing into account.
2) The final line of the SPMD block should be:
result = gcat(var,2,1);
Where var is the composite variable. This is a global concatenation of all OUTPUT variables, storing the result at lab index 1.
3) After the SPMD block, add the following code:
output = result{1};
This takes the globally concatenated values stored in 'result' and moves them into the base workspace in the variable 'output'.
Más respuestas (0)
Ver también
Categorías
				Más información sobre Logical en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

