Davide Rigato
Davide Rigato

Reputation: 13

How to divide in groups a set of ROIs according to their y-coordinate?

I am writing a code in MATLAB about extracting the calcium signal in a root, having a video as input source. I managed to place the ROIs, from which to extract the signal, on both the boundary and the skeleton of the root. So far so good. The point is to group the ROIs on the edge together (maybe in 5 groups) according to their y-coordinates and extract the signal as mean from those groups. You can find the image of the various implementation below:

Original frame

Frame + ROIs

ROIs on the edge


This is the code for the ROIs on the edge:

%Here I create the ROIs on the border----------------------------------
    %With "find" I look for the starting point of the edge
    [row_edge, col_edge] = find(frame_edge==1,1);
    %With bwtraceboundary I select the row and the column of the edge SEQUENTIALLY 
    boundary_edge = bwtraceboundary(frame_edge, [row_edge col_edge],'S');
    
    %Counter of the number of centers
    u = 1;
    %Initialization of the number of centers
    centers_edge(1,1,i) = boundary_edge(1,1);
    centers_edge(1,2,i) = boundary_edge(1,2);

    for e = 1:size(boundary_edge,1)
        temp_x_edge = boundary_edge(e,2);
        temp_y_edge = boundary_edge(e,1);
        dist_edges = sqrt((centers_edge(u,1,i)-temp_x_edge).^2+(centers_edge(u,2,i)-temp_y_edge).^2);
        if dist_edges > 40
            u = u+1;
            centers_edge(u,1,i) = temp_x_edge;
            centers_edge(u,2,i) = temp_y_edge;
        end
    end

This is what I tried to do to group the ROIs' centers:

%Here I try to divide the centers_edge in sections---------------------

    delta_y = floor((max(centers_edge(:,2,i))-min(centers_edge(:,2,i)))/5);
    
    %Position (x,y) of the centers belonging to one of the 5 classes
    for k  = 1:5
        y_delta = find((centers_edge(:,2,i)>(k-1)*delta_y) & (centers_edge(:,2,i) < k*delta_y));
        coordinates_group_x{k} = centers_edge(y_delta,1,i); %x-coordinates
        coordinates_group_y{k} = centers_edge(y_delta,2,i); %y-coordinates
    end

This is the plot of everything:

subplot(152)
 imshow(frame_elab)

for u = 1:size(centers_edge,1)
                h_edge = drawcircle('Center', [centers_edge(u,1,i) centers_edge(u,2,i)],'Radius', 20, ...
                    'Color', 'y', 'LineWidth', 1); %Here I create the circular ROI
                mask_edge = createMask(h_edge); % Here I create a mask such that it has only ones insde the ROI
                temp_image_edge = frame_ratio_elab.*mask_edge; % Here I isolate the pixels with the mask from the frame_ratio
                temp_ROI_edge = frame_thresh_emp_filt.*mask_edge;% Here I apply the ROI to the frame_threshold 
        
                area_ROIs_edge(u,i) = sum(temp_image_edge(:))/(sum(temp_ROI_edge(:)));
        end

The last part is a bit messy. The "frame_ratio_elab" is the original frame with a BW threshold applied to it and the "frame_thresh_emp_filt" is the same thing but with a median filter applied to it (This is not important for the sake of the problem). The final question, again, is how do I group "area_ROIs_edge" according to the y-coordinate of the ROIs that constitute it?

Upvotes: 0

Views: 39

Answers (0)

Related Questions