Facing error in combining two m-files

1 Ansicht (letzte 30 Tage)
Explorer
Explorer am 20 Jan. 2014
Kommentiert: Explorer am 21 Jan. 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 Kommentare
Explorer
Explorer am 20 Jan. 2014
Sure! I forgot to attach that file.
Explorer
Explorer am 20 Jan. 2014
Bearbeitet: Explorer am 20 Jan. 2014
I am expecting output as shown here

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Bruno Pop-Stefanov
Bruno Pop-Stefanov am 20 Jan. 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.

Weitere Antworten (0)

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by