def postResize(self): print(" Post resize") data_name = self._keyword data_files = dataFiles(data_name) for data_file in data_files: data_filename = os.path.basename(data_file) C_8U = loadRGB(data_file) if C_8U is None: os.remove(data_file) print(" - Delete: %s" % data_filename) continue h, w = C_8U.shape[0:2] opt_scale = 800.0 / float(h) opt_scale = max(opt_scale, 800.0 / float(w)) opt_scale = min(opt_scale, 1.0) h_opt = int(opt_scale * h) w_opt = int(opt_scale * w) C_8U_small = cv2.resize(C_8U, (w_opt, h_opt)) saveRGB(data_file, C_8U_small) print(" - Resized: %s" % data_filename)
def loadData(data_name, data_id): data_file = dataFile(data_name, data_id) if data_file is None: return None return loadRGB(data_file)
def postResize(self): print " Post resize" data_name = self._keyword data_files = dataFiles(data_name) for data_file in data_files: data_filename = os.path.basename(data_file) C_8U = loadRGB(data_file) if C_8U is None: os.remove(data_file) print " - Delete: %s" % data_filename continue h, w = C_8U.shape[0:2] opt_scale = 800.0 / float(h) opt_scale = max(opt_scale, 800.0 / float(w)) opt_scale = min(opt_scale, 1.0) h_opt = int(opt_scale * h) w_opt = int(opt_scale * w) C_8U_small = cv2.resize(C_8U, (w_opt, h_opt)) saveRGB(data_file, C_8U_small) print " - Resized: %s" % data_filename
def createMultiImagePixels(data_name, data_ids): rgb_pixels = [] num_cols = 3 num_rows = (len(data_ids) + 2) / num_cols fig = plt.figure(figsize=(10, 7)) fig.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95, wspace=0.1, hspace=0.1) font_size = 15 plot_id = 1 for data_id in data_ids: image_file = dataFile(data_name, data_id) image = loadRGB(image_file) rgb_pixels.extend(ColorPixels(image).rgb()) fig.add_subplot(num_rows, num_cols, plot_id) plt.imshow(image) plt.axis("off") plot_id += 1 rgb_pixels = np.array(rgb_pixels) multi_image = np.array(rgb_pixels).reshape(1, -1, 3) multi_tile = figure2numpy(fig) return multi_image, multi_tile
def histogram3DResult(image_file, num_bins=32, image=None, tile=None): image_name = os.path.basename(image_file) if image is None: image_name = os.path.basename(image_file) image_name = os.path.splitext(image_name)[0] image = loadRGB(image_file) if tile is None: tile = image fig_w = 10 fig_h = 6 fig = plt.figure(figsize=(fig_w, fig_h)) fig.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95, wspace=0.02, hspace=0.2) font_size = 15 fig.suptitle("Hisotogram 3D", fontsize=font_size) h, w = image.shape[:2] fig.add_subplot(231) plt.title("Original Image: %s x %s" % (w, h), fontsize=font_size) plt.imshow(tile) plt.axis('off') color_spaces = ["rgb", "Lab", "hsv"] plot_id = 234 for color_space in color_spaces: ax = fig.add_subplot(plot_id, projection='3d') plotHistogram3D(image, num_bins, color_space, ax) plot_id += 1 result_name = image_name + "_hist3D" result_file = resultFile(result_name) plt.savefig(result_file, transparent=True)
def createMultiImagePixels(data_name, data_ids): rgb_pixels = [] num_cols = 3 num_rows = (len(data_ids) + 2) / num_cols fig = plt.figure(figsize=(10, 7)) fig.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95, wspace=0.1, hspace=0.1) font_size = 15 plot_id = 1 for data_id in data_ids: image_file = dataFile(data_name, data_id) image = loadRGB(image_file) rgb_pixels.extend(ColorPixels(image).rgb()) fig.add_subplot(num_rows, num_cols, plot_id) plt.imshow(image) plt.axis('off') plot_id += 1 rgb_pixels = np.array(rgb_pixels) multi_image = np.array(rgb_pixels).reshape(1, -1, 3) multi_tile = figure2numpy(fig) return multi_image, multi_tile
def histogram1DResult(image_file, num_bins=32, image=None, tile=None): image_name = os.path.basename(image_file) if image is None: image_name = os.path.basename(image_file) image_name = os.path.splitext(image_name)[0] image = loadRGB(image_file) if tile is None: tile = image fig_w = 10 fig_h = 6 fig = plt.figure(figsize=(fig_w, fig_h)) fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.95, wspace=0.3, hspace=0.2) font_size = 15 fig.suptitle("Hisotogram 1D", fontsize=font_size) h, w = image.shape[:2] fig.add_subplot(231) plt.title("Original Image: %s x %s" % (w, h), fontsize=font_size) plt.imshow(tile) plt.axis('off') color_targets = [["Lab", 0], ["hsv", 0], ["hsv", 2]] plot_id = 234 for color_target in color_targets: ax = fig.add_subplot(plot_id) color_space, channel = color_target plotHistogram1D(image, num_bins, color_space, channel, ax) plot_id += 1 result_name = image_name + "_hist1D" result_file = resultFile(result_name) plt.savefig(result_file, transparent=True)
# -*- coding: utf-8 -*- # # @package color_histogram.examples.hist_1d # # Minimal example of 1D color histograms. # @author tody # @date 2015/08/29 from color_histogram.io_util.image import loadRGB from color_histogram.core.hist_1d import Hist1D import matplotlib.pyplot as plt from color_histogram.datasets.datasets import dataFile image_file = dataFile("flower", 0) # Load image. image = loadRGB(image_file) # 16 bins, Lab color space, target channel L ('Lab'[0]) hist1D = Hist1D(image, num_bins=16, color_space='Lab', channel=0) fig = plt.figure() ax = fig.add_subplot(111) hist1D.plot(ax) plt.show()
# -*- coding:utf-8 -*- import glob, os, shutil import numpy as np from color_histogram.io_util.image import loadRGB from color_histogram.core.hist_1d import Hist1D from color_histogram.core.hist_3d import Hist3D import matplotlib.pyplot as plt srcpath = "E:\\match_sample\\someone\\1494054534-9\\1494056641-0\\" filelist = glob.glob(r'%s*.jpg' % srcpath) for afile in filelist: image = loadRGB(afile) # 16 bins, Lab color space, target channel L ('Lab'[0]) #hist1D = Hist1D(image, num_bins=16, color_space='rgb') hist3D = Hist3D(image, num_bins=64, color_space='rgb') fig = plt.figure() ax = fig.add_subplot(111, projection='3d') hist3D.plot(ax) plt.show()
from color_histogram.io_util.image import loadRGB from color_histogram.core.hist_3d import Hist3D import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np from scipy.spatial import ConvexHull # Load image. image = loadRGB('7.png') # 16 bins, rgb color space hist3D = Hist3D(image, num_bins=255, color_space='Lab') fig = plt.figure() ax = fig.add_subplot(111, projection='3d') hist3D.plot(ax) vs = [[62.0070164688, -23.4659787223, -12.9463413357], [100.409562663, 2.9859782616, -9.0728531732], [-4.85583594611, -8.57160085891, -6.62002503029], [52.7760787206, 74.0586148013, 69.0603637824], [7.93947944138, 31.7299007512, 21.6140843711], [17.979327872, 12.9425661512, -40.582473457], [69.7839261866, -16.8646459746, -40.0210475383], [109.763141803, -18.5892033919, -0.540175787924], [2.59630991524, -13.0235296149, 15.9177894542], [80.81699057114272, 10.765956215340807, 74.30941946766103]] vs = np.asarray(vs) hull = ConvexHull(vs) ax.plot(vs.T[0], vs.T[1], vs.T[2], "ko") for s in hull.simplices: s = np.append(s, s[0]) # Here we cycle back to the first coordinate