Prev: Variable renaming in Editor
Next: problem with s-function when building real time windows in external mode
From: Christian on 6 Aug 2010 05:35 Hello, my sort-code is nor working in the right way: Its result is: Sums = 0 0 0 0 2 1 1 3 2 1 3 0 2 1 3 0 BUT the correct result should be: Sums = 0 0 0 0 2 1 1 3 2 1 0 3 2 1 0 3 I want to get all channels (=0) of my 3dim test-data (5 slices). The belonging to a channel is delivered by the center of each 0-area (means) from slice to slice. Problem: My slice-to-slice-code produces a wrong result a soon as a channel is not going through the whole data. --> Reason: Index-shifting Analysing the whole data by bwlablen doesn't fix the problem because I need a detailed slice-to-clice-result. Do you have a good hint for me? Thank you. Christian CODE: clear all; close all; % A(x,y;z) code runs in direction y (=j) % --> from "left to right" through the data %======================================================================== %Data A(:,:,1) = [0 1 1 1 1; 0 1 1 1 1; 0 1 1 1 1; 0 1 1 1 1; 0 1 1 1 1; 0 1 1 1 1; 1 1 1 1 1] A(:,:,2) = [0 0 0 0 0; 0 0 0 0 0; 0 1 1 1 1; 0 0 0 1 1; 0 1 1 1 1; 0 0 0 0 0; 1 1 1 1 1] A(:,:,3) = [0 1 1 1 1; 0 1 1 1 1; 0 1 1 1 1; 0 1 1 1 1; 0 1 1 1 1; 1 1 1 1 1; 1 1 1 1 1] A(:,:,4) = [0 1 1 1 1; 0 1 1 1 1; 0 1 1 1 1; 0 1 1 1 1; 0 0 0 0 0; 0 0 0 0 0; 0 0 0 0 0] %======================================================================= B = A; %Step3 (Goall: SUMS = Number of channels and their size in each slice) for j = 1:(size(B,2)-1) slice1 = bwlabeln(~B(:,j,:)); %labeling each slice peak1 = max(max(slice1)); %max index of each slice k=1; %for SUMS-Matrix (?!Reason 4 mistake!?) for i = 1:peak1 [x , y] = find(slice1==i); mx = round(mean(x)); %0-area centers my = round(mean(y)); %Test - Channel also in next slice - according to center of previous slice: if B(mx,j+1,my) == 0 Sums(j,k) = sum(sum(slice1==i)); k=k+1; end end end Sums
From: ImageAnalyst on 6 Aug 2010 07:03 Why are you doing a multi-dimensional labeling (with bwlabeln instead of bwlabel) yet not taking advantage of the multidimensionality of it? In other words, why are you doing it slice by slice? Also, look at the second argument returned by the label routines - it's the count of the number of objects found. And I'm not sure what this means: "get all channels (=0) " What does the =0 have to do with anything?
From: Christian on 6 Aug 2010 07:19 > "get all channels (=0) " What does the =0 have to do with anything? Some more Information: The data is like a wall with holes hit by water: A complete 0-channel (hole) lets the water through the data. > Why are you doing a multi-dimensional labeling (with bwlabeln instead > of bwlabel) Slice1 = bwlabel(~B(:,j,:)) does not work >why are you doing it slice by slice? Bwlabeln for the whole data doesn't give me any infomation about the number of all channels and the size of each channel.
From: ImageAnalyst on 6 Aug 2010 17:48 slice1 is a 3D array - were you expecting a 2D array? Maybe that's your problem. Maybe you need to use the squeeze() function.
From: Christian on 8 Aug 2010 07:24
> slice1 is a 3D array - were you expecting a 2D array? Maybe that's > your problem. Maybe you need to use the squeeze() function. I don't think that's the problem. The result in SUMS is already close to a good solution. As I said in the code: The real problem is the "k" index. I need an alternative for that part. |