Iteratively Processing Connected Components: How to relabel components, while at the same time 'remembering' components with 'old' labels.

2 views (last 30 days)
This question was originally, mistakenly posted in the Newsgroup forum:
Dear Matlab Users,
My problem relates to relabeling connected components, while at the same time 'remembering' components with 'old' labels.
I have a function which iteratively applies some processing to data. This processing causes some objects within the dataset to be eliminated, some split and others remain largely unchanged. I then separate out the connected components of the dataset and in a subroutine run more tests on the components which were split as well as those which were split in previous iterations. Then the whole process starts again.
I have code for everything except the subroutine; I don't know how to identify previously split components since the function applies new labels to the data on each iteration.
In (bad) pseudo code:
1. original_data = data
for i < number of timesteps
2. process data
3. separate out connected components of processed data
4. using original_data, test whether components in processed data have been split
5. if split_data is true OR if data was split in previous iterations
for i < number of split components
run tests on split components
end
repeat.
end
Matlab code: (I'm sorry if this is way too much detail)
% variables:
% phi_b - original data.
% phi_t - processed data
% setup variables
phi_t = phi_b;
for i < number of timesteps
% 2. Process data
phi_t = process_data(phi_t)
% 3. find connected components (cc)
roiCC=bwconncomp(phi_t,18);
% 4. using original_data, test whether components in processed data have been split
% 4.1 Compute intersection between original data and processed data
phi = logical(phi_t) & logical(phi_b);
% 4.2 Process each component in turn
for j=1:length(roiCC.PixelIdxList)
% isolate each component in turn:
binaryMask=false(Nx,Ny,Nz);
objectPosition=roiCC.PixelIdxList{idx(j)};
binaryMask(objectPosition)=1;
% 4.3 Compute intersection
indicator = phi & binaryMask;
% Check if 'indicator' contains multiple ccs
CCindicator = bwconncomp(indicator,18);
numIndCompnts = CCindicator.NumObjects;
% This is where the problem is:
if numIndCompnts > 1
for p=1:numIndCompnts
binaryMaskInd=false(Nx,Ny,Nz);
objectPositionInd=CCindicator.PixelIdxList{p};
binaryMaskInd(objectPositionInd)=1;
% Run More Processing
Testresults = runMoreProcessing(binaryMaskInd);
end
end
end
end
As you can see, in the 'last' section I am merely processing the 'newly' split components, not the previously split ones.
If anybody has suggestions on how to identify the previously split components, which have subsequently been modified (via step 2). I would be very happy!
In addition, if anyone can highlight some redundancy in my code, separate to the above problem, I would very much appreciate it.
-n

Answers (0)

Categories

Find more on Startup and Shutdown 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!