added spatial colour and texture
added imload normalisation added fixes for 0 edge histogram
This commit is contained in:
parent
1dea8e54d5
commit
83769a8449
File diff suppressed because one or more lines are too long
172
opencv.ipynb
172
opencv.ipynb
File diff suppressed because one or more lines are too long
@ -43,7 +43,7 @@ def extract_spatial_texture(height: int,
|
||||
for seg in segments:
|
||||
img_edge = edge.get_edge_info(pixels=seg)
|
||||
hist = edge.get_edge_angle_hist(img_edge, bins=bins, threshold=threshold)
|
||||
descriptor = np.append(descriptor, hist[0])
|
||||
descriptor = np.append(descriptor, hist)
|
||||
return descriptor
|
||||
|
||||
if images is not None:
|
||||
@ -68,7 +68,7 @@ def extract_spatial_average_rgb(height: int,
|
||||
raise KeyError('no image provided')
|
||||
|
||||
def extract(i):
|
||||
segments = grid_image(height, width, pixels)
|
||||
segments = grid_image(height, width, i)
|
||||
descriptor = np.array([])
|
||||
for seg in segments:
|
||||
descriptor = np.append(descriptor, rgb.extract_average_rgb(pixels=seg))
|
||||
@ -84,3 +84,37 @@ def extract_spatial_average_rgb(height: int,
|
||||
image.descriptor = extract(image.pixels)
|
||||
else:
|
||||
return extract(pixels)
|
||||
|
||||
|
||||
def extract_spatial_avg_rgb_texture(height: int,
|
||||
width: int,
|
||||
bins: int,
|
||||
threshold: float,
|
||||
pixels: np.array = None,
|
||||
image: Image = None,
|
||||
images: List[Image] = None):
|
||||
|
||||
if pixels is None and image is None and images is None:
|
||||
raise KeyError('no image provided')
|
||||
|
||||
def extract(i):
|
||||
segments = grid_image(height, width, i)
|
||||
descriptor = np.array([])
|
||||
for seg in segments:
|
||||
img_edge = edge.get_edge_info(pixels=seg)
|
||||
hist = edge.get_edge_angle_hist(img_edge, bins=bins, threshold=threshold)
|
||||
descriptor = np.append(descriptor, hist)
|
||||
|
||||
descriptor = np.append(descriptor, rgb.extract_average_rgb(pixels=seg))
|
||||
return descriptor
|
||||
|
||||
if images is not None:
|
||||
length = len(images)
|
||||
for index, image in enumerate(images):
|
||||
logger.debug(f'generating {index} of {length}')
|
||||
image.descriptor = extract(image.pixels)
|
||||
return
|
||||
elif image is not None:
|
||||
image.descriptor = extract(image.pixels)
|
||||
else:
|
||||
return extract(pixels)
|
||||
|
@ -25,7 +25,15 @@ def load_set(path: str) -> List[Image]:
|
||||
logger.info(f'loading set from {path}')
|
||||
|
||||
files = load_path(path)
|
||||
images = [Image(cv2.imread(i))[:, :, ::-1] for i in files]
|
||||
images = [Image(cv2.normalize(
|
||||
cv2.imread(i)[:, :, ::-1]. # slice to go from BGR to RGB
|
||||
astype('float'),
|
||||
None, # output obj none
|
||||
alpha=0,
|
||||
beta=1,
|
||||
norm_type=cv2.NORM_MINMAX,
|
||||
dtype=cv2.CV_32F)
|
||||
) for i in files]
|
||||
return images
|
||||
|
||||
|
||||
@ -40,7 +48,14 @@ def load_msrc(path: str, descriptor_path=None) -> List[Image]:
|
||||
file_name_split = file_name.split('_')
|
||||
category = int(file_name_split[0])
|
||||
name = int(file_name_split[1])
|
||||
images.append(Image(cv2.imread(image)[:, :, ::-1],
|
||||
images.append(Image(cv2.normalize(
|
||||
cv2.imread(image)[:, :, ::-1]. # slice to go from BGR to RGB
|
||||
astype('float'),
|
||||
None, # output obj none
|
||||
alpha=0,
|
||||
beta=1,
|
||||
norm_type=cv2.NORM_MINMAX,
|
||||
dtype=cv2.CV_32F),
|
||||
category=category,
|
||||
name=name))
|
||||
|
||||
|
@ -21,7 +21,11 @@ def get_edge_angle_hist(edge: Edge, bins: int, threshold: float):
|
||||
|
||||
bin_val = m.floor((edge.angle[i, j] / (2*np.pi)) * bins)
|
||||
angle_vals.append(bin_val)
|
||||
return np.histogram(angle_vals, bins=bins, density=True)
|
||||
|
||||
if len(angle_vals) > 0:
|
||||
return np.histogram(angle_vals, bins=bins, density=True)[0]
|
||||
else:
|
||||
return np.zeros(bins)
|
||||
|
||||
|
||||
def get_edge_info(pixels: np.array = None,
|
||||
@ -39,7 +43,7 @@ def get_edge_info(pixels: np.array = None,
|
||||
grey = cv2.cvtColor(i, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
if blur is True:
|
||||
i = convolve2d(grey, np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]]) / 9)
|
||||
grey = convolve2d(grey, np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]]) / 9)
|
||||
|
||||
dx = convolve2d(grey, kx)
|
||||
dy = convolve2d(grey, ky)
|
||||
|
Loading…
Reference in New Issue
Block a user