How can we compute all the Haar-like features of all types using scikit-image function haar_like_feature? This is what I have tried (a simple example for computing all the features of type 2x):
from skimage.feature import haar_like_feature
from skimage.transform import integral_image
img = np.array([[1, 2],
[1, 3]])
ii = integral_image(img)
features = haar_like_feature(ii, 0, 0, ii.shape[1], ii.shape[0], 'type-2-x')
print(features)
[1, 2]
However I would expect to get [1, 2, 3], because we should also consider a rectangle feature covering the whole image resulting in the feature value (2 + 3) - (1 + 1) = 3.
I also checked the Viola-Jones paper and they have the following number of features:
type-2-x: 43200
type-2-y: 43200
type-3-x: 27600
type-3-y: 27600
type-4: 20736
total: 162336
(source: An Analysis of the Viola-Jones Face Detection Algorithm)
However the number of features produced by skimage.feature.haar_like_feature is different:
img = np.random.randint(0, 256, (24,24))
ii = integral_image(img)
total = 0
for feature_type in ['type-2-x', 'type-2-y', 'type-3-x', 'type-3-y', 'type-4']:
features = haar_like_feature(ii, 0, 0, ii.shape[1], ii.shape[0], feature_type)
print(f"{feature_type}: {len(features)}")
total += len(features)
print("\ntotal:", total)
:
type-2-x: 43056
type-2-y: 43056
type-3-x: 27508
type-3-y: 27508
type-4: 20736
total: 161864
So it seems that there are 472 features missing in this computation. Am I doing it wrong? What parameters should I pass to the function haar_like_feature() to get all the features?
Update: there seems to be a bug in the implementation of the function haar_like_feature https://github.com/scikit-image/scikit-image/issues/4818
for here,just wanna share:
from here : img = np.array([[1, 2], [1, 3]])
to : img = np.random.randint(0, 256, (12,12))
try to increase the input size of np.array() or image size..to for example 12x12.