Facing error in combining two m-files
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Explorer
le 20 Jan 2014
Commenté : Explorer
le 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/155352/image.jpeg)
Input Image for hand detection
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/155353/image.jpeg)
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 commentaires
Réponse acceptée
Bruno Pop-Stefanov
le 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!