def transform(image): thumbsize = 50 thumb = misc.imresize(image, (thumbsize, thumbsize), interp='nearest') thumb = op.normalizeImage(thumb) thumb = rgb2gray(thumb) transf = frequencyFeaturesImage(thumb, selectedclass=21) return transf
def normalizedColorDistances(image, r_steps=2, g_steps=2, b_steps=2): normalized = op.normalizeImage(image) features = [] for r in range(r_steps): for g in range(g_steps): for b in range(b_steps): color = numpy.array( [r, g, b]) / (numpy.linalg.norm([r, g, b]) + 0.01) * 255 distances = numpy.linalg.norm(normalized - color, axis=2) features.append(distances.mean()) features.append(numpy.std(distances)) return numpy.array(features)
def splitColorFeatures(image, splits=3): features = np.zeros(3 * splits * splits) normalized = op.normalizeImage(image) width = len(normalized) height = len(normalized[0]) for i in range(splits): for j in range(splits): index = (i * splits + j) * 3 subImage = normalized[height / splits * i:height / splits * (i + 1), width / splits * j:width / splits * (j + 1), :] subFeatures = calculateColorFeatures(subImage) features[index] = subFeatures[0] features[index + 1] = subFeatures[1] features[index + 2] = subFeatures[2] return features
def normalizedColorFeatures(image, mean=True, std=True, skew=True, kurtosis=True): return color_features(op.normalizeImage(image), mean, std, skew, kurtosis)
def calculateNormalizedColorFeatures(image): return calculateColorFeatures(op.normalizeImage(image))
import data_loading as loader import feature_extraction as extractor from matplotlib import pyplot as plot from mpl_toolkits.mplot3d.axes3d import Axes3D darkImage = ndimage.imread("train/diamonds/B9/00585_09701.png") normalImage = ndimage.imread("train/diamonds/B9/00042_00233.png") comparison = plot.figure() standardDark = comparison.add_subplot(2, 2, 1) standardDark.imshow(darkImage) standardNormal = comparison.add_subplot(2, 2, 2) standardNormal.imshow(normalImage) normalDark = comparison.add_subplot(2, 2, 3) normalDark.imshow(op.normalizeImage(darkImage)) normalNormal = comparison.add_subplot(2, 2, 4) normalNormal.imshow(op.normalizeImage(normalImage)) images = loader.loadTrainingImages() classA = list(filter(lambda i: i[2] == "D1a", images)) classB = list(filter(lambda i: i[2] == "B9", images)) classC = list(filter(lambda i: i[2] == "B5", images)) fig = plot.figure() axes = fig.add_subplot(1, 2, 1, projection='3d', title='Using Colors',
def getClosestPointOfPlace(self, pt_start, pl_id, mc_name, dbg_output_path=None): pl = self.getPlaceById(pl_id, mc_name) mask = self.getMask(mc_name) res = mask.getResolution() orig = mask.getOrigin() # Shrink the mask radius_m = 0.4 radius_px = int(radius_m / res) op_enl = iop.OperationEnlarge(radius_px, 0) img_mask = iop.binaryImage(mask.getImage(), 0.5) img_mask_shrinked = op_enl.compute({'img': img_mask})['img'] # Shrink the place radius_m = 0.1 radius_px = int(radius_m / res) op_enl2 = iop.OperationEnlarge(radius_px, 0) img_pl = iop.binaryImage(pl.getEmbeddedImage().getImage(), 0.5) img_pl_shrinked = op_enl2.compute({'img': img_pl})['img'] if not dbg_output_path is None: cv2.imwrite(dbg_output_path + '/mask.png', iop.normalizeImage(img_mask)) cv2.imwrite(dbg_output_path + '/mask_shrinked.png', iop.normalizeImage(img_mask_shrinked)) phi_emb = mask.emptyCopy() ei.drawCircle(phi_emb, pt_start, int(0.1 / res), 1, -1) phi = 1 - 2 * phi_emb.getImage() if not dbg_output_path is None: cv2.imwrite(dbg_output_path + '/phi.png', iop.normalizeImage(phi)) phi = np.ma.MaskedArray(phi, 1 - img_mask_shrinked) start_pt_dist = skfmm.distance(phi, dx=1e-2).data start_pt_dist_max = np.max(start_pt_dist) start_pt_dist[img_mask_shrinked == 0] = start_pt_dist_max + 1 if not dbg_output_path is None: cv2.imwrite(dbg_output_path + '/start_pt_dist.png', iop.normalizeImage(start_pt_dist)) pl_dist_img = np.multiply(start_pt_dist, img_pl_shrinked) pl_dist_img[img_mask_shrinked == 0] = start_pt_dist_max + 1 pl_dist_img[img_pl_shrinked == 0] = start_pt_dist_max + 1 if not dbg_output_path is None: cv2.imwrite(dbg_output_path + '/pl_dist_img.png', iop.normalizeImage(pl_dist_img)) iy, ix = np.unravel_index(np.argmin(pl_dist_img, axis=None), pl_dist_img.shape) cv2.circle(img_mask, (ix, iy), 5, 2, thickness=1) if not dbg_output_path is None: cv2.imwrite(dbg_output_path + '/img_mask_goal.png', iop.normalizeImage(img_mask)) return (ix * res + orig[0], iy * res + orig[1])
# -*- coding: utf-8 -*- """ Created on Wed Nov 4 15:03:01 2015 @author: Rian """ import image_transformation_testing as plotter import image_operations as op #regular images plotter.plotTransformation(lambda x: x) #resized and cropped images plotter.plotTransformation(lambda x: op.cropAndResize(x, 0.10, 50)) #normalized images plotter.plotTransformation( lambda x: op.normalizeImage(op.cropAndResize(x, 0.10, 50)))