Here's an implementation with mahotas
from pylab import imshow import numpy as np import mahotas wally = mahotas.imread('DepartmentStore.jpg') wfloat = wally.astype(float) r,g,b = wfloat.transpose((2,0,1))
Divided into red, green and blue channels. Better to use floating point arithmetic, so we convert at the top.
w = wfloat.mean(2)
w is the white channel.
pattern = np.ones((24,16), float) for i in xrange(2): pattern[i::4] = -1
Create a template + 1, + 1, -1, -1 on the vertical axis. This is a shirt.
v = mahotas.convolve(rw, pattern)
Convert with red minus white. This will give a strong response when the shirt.
mask = (v == v.max()) mask = mahotas.dilate(mask, np.ones((48,24)))
Look for the maximum value and expand it to make it visible. Now we are reducing the whole image, with the exception of the region or interest:
wally -= .8*wally * ~mask[:,:,None] imshow(wally)
And we get
!
luispedro Nov 07 2018-12-12T00: 00Z
source share