help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Split data depending on values


From: Matthieu Chourrout
Subject: Split data depending on values
Date: Wed, 11 Jul 2018 15:34:22 +0200 (CEST)

Hi,
 
I currently have a set of randomly spread data in a 2048-by-2048 grid (non-integer values between 1 and 2048), arranged in an N-by-2 matrix with X,Y coordinates, and I would like to split these data for further analysis, starting from 4 quarters of 1024-by-1024 (but with the idea of splitting it again).
I also need to be able to extract the indexes as some other data is "paired" with this.

It's the same idea as the BLOCKPROC function, but I'm not working with an image at this point.

To be more precise, here is my data:

colors = "rgb";
for channel_id = 1:3
   regions.(colors(channel_id)) = regionprops(labels(:,:,2), ...
filtered_image(:,:,channel_id),'Area','SubarrayIdx','BoundingBox','WeightedCentroid','MaxIntensity','MinIntensity','PixelValues');
   centers_of_mass.(colors(channel_id)) = cat(1, regions.(colors(channel_id)).WeightedCentroid);
endfor
% centers_of_mass.r, centers_of_mass.g and centers_of_mass.b are my N-by-2 matrices

I tried to use some sorting and then split at the different thresholds, but maybe is there another more efficient way?
 

function [new_idx, splitting_idx] = split(data_to_rearrange, splitting_values)
 splitting_idx = [0 0 0];

 [rearranged_data, new_idx] = sortrows(data_to_rearrange, [1 2]);
 splitting_idx(2) = -1 + find(rearranged_data(:,1) > splitting_values(1),1);

 [rearranged_data(1:splitting_idx(2), :), tmp_idx] = sortrows(rearranged_data(1:splitting_idx(2), :), [2 1]);
 new_idx(1:splitting_idx(2)) = new_idx(1:splitting_idx(2))(tmp_idx);
 splitting_idx(1) = -1 + find(rearranged_data(1:splitting_idx(2),2) > splitting_values(2),1);
 [rearranged_data(splitting_idx(2)+1:end, :), tmp_idx] = sortrows(rearranged_data(splitting_idx(2)+1:end, :), [2 1]);
 new_idx(splitting_idx(2)+1:end) = new_idx(splitting_idx(2)+1:end)(tmp_idx);
 splitting_idx(3) = -1 + splitting_idx(2) + find(rearranged_data(splitting_idx(2)+1:end,2) > splitting_values(2),1);
endfunction

 

With this function and the piece of code below, I can achieve it for the quarters. But now I want to split it further.

 

[I4,s4] = split(centers_of_mass.g,[acquisition_parameters.camera.center.x acquisition_parameters.camera.center.y]);
 [I4,s4] = split(centers_of_mass.g,[1024 1024]);
 centers_of_mass.g = centers_of_mass.g(I4,:);
 centers_of_mass.r = centers_of_mass.r(I4,:);
 centers_of_mass.b = centers_of_mass.b(I4,:);

 splitted_centers_of_mass.mean_g = [ nanmean(centers_of_mass.g(1:s4(1),:)) ; ...
  nanmean(centers_of_mass.g(s4(1)+1:s4(2),:)) ; ...
  nanmean(centers_of_mass.g(s4(2)+1:s4(3),:)) ; ...
  nanmean(centers_of_mass.g(s4(3)+1:end,:)) ];
 splitted_centers_of_mass.mean_r = [ nanmean(centers_of_mass.r(1:s4(1),:)) ; ...
  nanmean(centers_of_mass.r(s4(1)+1:s4(2),:)) ; ...
  nanmean(centers_of_mass.r(s4(2)+1:s4(3),:)) ; ...
  nanmean(centers_of_mass.r(s4(3)+1:end,:)) ];
 splitted_centers_of_mass.mean_b = [ nanmean(centers_of_mass.b(1:s4(1),:)) ; ...
  nanmean(centers_of_mass.b(s4(1)+1:s4(2),:)) ; ...
  nanmean(centers_of_mass.b(s4(2)+1:s4(3),:)) ; ...
  nanmean(centers_of_mass.b(s4(3)+1:end,:)) ];

 
Or maybe I could use BLOCKPROC earlier in my script (the problem with this solution is that I may also split some of my labeled groups and get duplicates or corrupted data on the edges...)?
 
Thanks in advance,
        
Matthieu CHOURROUT

PS: I remember I have read a thread quoting a function to export pastable variables, so that you can directly work on my data, but I never managed to find it again: if you know it, could you also mention it please?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]