Borrar filtros
Borrar filtros

Facing error in combining two m-files

1 visualización (últimos 30 días)
Explorer
Explorer el 20 de En. de 2014
Comentada: Explorer el 21 de En. de 2014
I have two codes having names skin_detection5.m and hand_detection4.m
I am trying to combine these two m-files but getting error.
combination.m is a file in which I tried to combine above mentioned m-file.
Input Image for skin_detection5.m
Input Image for hand detection
Both skin_detection5.m and hand_detection4.m are working fine for given input images. But I am trying to make a one m-file so that I do can both things i.e. skin detection and hand detection by running one m-file. But getting error mentioned below:
Attempted to access sortingIndexes(2); index out of bounds because
numel(sortingIndexes)=1.
Error in combination (line 129)
handIndex = sortingIndexes(2); % The hand is the second biggest, face is biggest.
  3 comentarios
Explorer
Explorer el 20 de En. de 2014
Sure! I forgot to attach that file.
Explorer
Explorer el 20 de En. de 2014
Editada: Explorer el 20 de En. de 2014
I am expecting output as shown here

Iniciar sesión para comentar.

Respuesta aceptada

Bruno Pop-Stefanov
Bruno Pop-Stefanov el 20 de En. de 2014
The problem comes from line 111:
binaryImage = grayImage < 128;
Replace that line by the following:
binaryImage = ~grayImage;
Explanation:
In combination.m, you write (line 91):
grayImage = bin;
However, bin is a binary (or logical) image. Its values only are 0 or 1. When you write grayImage < 128, then you get an image with 1's everywhere because 0 and 1 are always < 128.
That explains the error you get at line 129: Since there is only one connected component in binaryImage (the whole image itself), then labeledImage (line 118), allAreas (line 127) and sortingIndexes (line 128) all correspond to only one connected component, instead of two or more (one for the head and one for the hand).
Therefore, when you try to access the second element of sortingIndexes, you get an error because sortingIndexes has only one element.

Más respuestas (0)

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