Facing error in combining two m-files

1 次查看(过去 30 天)
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 个评论
Explorer
Explorer 2014-1-20
Sure! I forgot to attach that file.
Explorer
Explorer 2014-1-20
编辑:Explorer 2014-1-20
I am expecting output as shown here

请先登录,再进行评论。

采纳的回答

Bruno Pop-Stefanov
Bruno Pop-Stefanov 2014-1-20
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by