src/utils.py
def rgb2greymat(im_shape,format="channels_first",dtype=_dtype):
	"""
	Matrix converting rgb image to greyscale
	"""
	if len(im_shape)==2:
		im_size_y, im_size_x = im_shape
		num_channels = 1
	else:
		if format=="channels_last":
			im_size_y, im_size_x, num_channels = im_shape
		else:
			num_channels, im_size_y, im_size_x = im_shape
	im_size = im_size_x*im_size_y*num_channels

	mat_size_x = im_size_x * im_size_y
	if num_channels>1:
		if format=="channels_last":
			return sp.kron( sp.eye(mat_size_x,dtype=dtype), np.array([[0.2125,0.7154,0.0721]],dtype=dtype) )
		else:
			return sp.kron( np.array([[0.2125,0.7154,0.0721]],dtype=dtype), sp.eye(mat_size_x,dtype=dtype) )
	else:
		return sp.eye(mat_size_x,dtype=dtype)

	Matrix converting rgb image to greyscale
	
Matrix converting rgb image to greyscale
Matrix converting rgb image to greyscale
def rgb2greymat(im_shape,format="channels_first",dtype=_dtype):
	if len(im_shape)==2:
		im_size_y, im_size_x = im_shape
		num_channels = 1
	else:
		if format=="channels_last":
			im_size_y, im_size_x, num_channels = im_shape
		else:
			num_channels, im_size_y, im_size_x = im_shape
	im_size = im_size_x*im_size_y*num_channels
	mat_size_x = im_size_x * im_size_y
	if num_channels>1:
		if format=="channels_last":
			return sp.kron( sp.eye(mat_size_x,dtype=dtype), np.array([[0.2125,0.7154,0.0721]],dtype=dtype) )
		else:
			return sp.kron( np.array([[0.2125,0.7154,0.0721]],dtype=dtype), sp.eye(mat_size_x,dtype=dtype) )
	else:
		return sp.eye(mat_size_x,dtype=dtype)
def rgb2greymat ( im_shape , format = "channels_first" , dtype = _dtype ) : if len ( im_shape ) == 2 : im_size_y , im_size_x = im_shape num_channels = 1 else : if format == "channels_last" : im_size_y , im_size_x , num_channels = im_shape else : num_channels , im_size_y , im_size_x = im_shape im_size = im_size_x * im_size_y * num_channels mat_size_x = im_size_x * im_size_y if num_channels > 1 : if format == "channels_last" : return sp . kron ( sp . eye ( mat_size_x , dtype = dtype ) , np . array ( [ [ 0.2125 , 0.7154 , 0.0721 ] ] , dtype = dtype ) ) else : return sp . kron ( np . array ( [ [ 0.2125 , 0.7154 , 0.0721 ] ] , dtype = dtype ) , sp . eye ( mat_size_x , dtype = dtype ) ) else : return sp . eye ( mat_size_x , dtype = dtype )
Matrix converting rgb image to greyscale
Matrix converting rgb image to greyscale
"""
	Matrix converting rgb image to greyscale
	"""
im_shape
format
dtype