doubt regarding bwconncomp example.

2 visualizaciones (últimos 30 días)
Meghana Dinesh
Meghana Dinesh el 21 de Ag. de 2015
Comentada: Image Analyst el 29 de Ag. de 2015
This is a small doubt.....I'm stuck in the second example given for bwconncomp by Mathworks. This example removes the group of pixels having largest pixels connected (in an 8 connected neighbourhood):
BW = imread('text.png');
imshow(BW);
CC = bwconncomp(BW);
numPixels = cellfun(@numel,CC.PixelIdxList);
[biggest,idx] = max(numPixels);
BW(CC.PixelIdxList{idx}) = 0;
figure, imshow(BW);
I want to change the code to erase groups of pixels which have between 20 to 70 connected pixels (in their 8 connected neighbourhood). How can I do this?
If I do:
idx = numPixels < 70;
I get an error saying : " Maximum variable size allowed by the program is exceeded."
  8 comentarios
Walter Roberson
Walter Roberson el 28 de Ag. de 2015
It looks like you are trying to find a maximum, but it is not clear what you are trying to find a maximum of.
idx = 20 <= numPixels & numPixels <= 70;
valididx = find(idx);
validsizes = numPixels(idx);
if isempty(valididx)
lastvalid = [];
else
lastvalid = valididx(end);
end
[sizelargest, idxlargest] = max(validsizes);
ccidxlargest = valididx(idxlargest);
lastvalid would be for the case where you want to find the index (into CC) of the last cluster that is in the size range -- the maximum being taken over the indices
ccidxlargest would be for the case whee you want to find the index (into CC) of the largest cluster that is left after you isolate down to that range of sizes -- the maximum being taken over the remaining sizes.
Meghana Dinesh
Meghana Dinesh el 28 de Ag. de 2015
Maybe my approach is wrong.
This is my goal: I have a pointCloud (a 3D matrix including Inf, NaN and finite values). I want to remove the groups of all those points ("remove" i.e., make them = NaN) which have lesser than N (say, 100) points connected to it (in a 26-connectivity neighbourhood).
In order to do this, I am performing the steps mentioned above (converting all finite values to logical and applying bwconncomp).
Are my steps right?

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 22 de Ag. de 2015
Use bwareafilt instead.
  2 comentarios
Meghana Dinesh
Meghana Dinesh el 24 de Ag. de 2015
Editada: Meghana Dinesh el 24 de Ag. de 2015
My data is in 3D.
Image Analyst
Image Analyst el 29 de Ag. de 2015
If you want to " want to remove the groups of all those points ("remove" i.e., make them = NaN) which have lesser than N (say, 100) points connected to it (in a 26-connectivity neighbourhood)." then the function you want to use is definitely 100% bwareaopen(). It's meant for exactly that. No need to get PixelIdxList at all.

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 28 de Ag. de 2015
N = 100;
a = imread('text.png');
c = a;
c(~isfinite(c)) = 0;
BW = logical(c);
CC = bwconncomp(BW);
numPixels = cellfun(@numel,CC.PixelIdxList);
idx = numPixels < N;
unwantedCC = CC(idx);
unwantedpixels = vertcat(unwantedCC.PixelIdxList);
b = a;
b(unwantedpixels) = NaN;
  6 comentarios
Meghana Dinesh
Meghana Dinesh el 29 de Ag. de 2015
:D Nevermind! Anyway, thanks for your help so far.
I am still not able to execute since the variable unwantedpixels is a cell. So the line:
b(unwantedpixels) = NaN;
gives an error saying: Function 'subsindex' is not defined for values of class 'cell'.
Walter Roberson
Walter Roberson el 29 de Ag. de 2015
unwantedpixels = cell2mat(CC.PixelIdxList(idx));

Iniciar sesión para comentar.

Categorías

Más información sobre Image Processing Toolbox 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!

Translated by