예제 #1
0
import sys
sys.path.insert(0, __folder_params.home)
import utils

from skimage import exposure
import cv2

def processHistogram(img_path, radius = 15):
    """ Extracts histogram for each color channel. """
    img = cv2.imread(img_path)
    final_path = utils.adress_file(img_path, "ColorHistogram")

    # http://scikit-image.org/docs/dev/api/skimage.exposure.html#skimage.exposure.histogram
    R, G, B = img[:, :, 2], img[:, :, 1], img[:, :, 0]
    Rhistogram = exposure.histogram(R)
    Ghistogram = exposure.histogram(G)
    Bhistogram = exposure.histogram(B)

    with open(final_path, 'w+') as f:
        for histogram in (Rhistogram, Ghistogram, Bhistogram):
            values, bins = histogram
            for v, b in zip(values, bins):
                f.write("%d:%d " % (b, v))
            f.write("\n")

if __name__ == "__main__":
    utils.FeatureExtractor("image", processHistogram).run()
    #a = FeatureExtractor("image", processHistogram)
    #print(next(a.data_iterator))
    #processHistogram(next(a.data_iterator))
예제 #2
0
                     input_shape,
                     mode='constant',
                     clip=True,
                     preserve_range=True)
        X[i, :, :, :] = img

    out = model.predict(X)

    for i, pred in enumerate(out):
        with open(final_paths[i], 'w+') as f:
            for i, v in enumerate(pred):
                if v > 0:
                    f.write("%d:%e " % (i, v))
            f.write("\n")


if __name__ == "__main__":
    #FeatureExtractor("image", processInceptionV3).run()
    a = utils.FeatureExtractor("image", processDnn)
    images_paths = [i for i in a.data_iterator]
    batch = 32

    batches = []
    for i in range(len(images_paths) // 32):
        batches.append(images_paths[i * 32:(i + 1) * 32])
    batches.append(images_paths[(i + 1) * 32:])
    model = get_inceptionV3()

    for img_batch in tqdm(batches, total=len(batches)):
        processDnn(img_batch, model)
예제 #3
0
	def perform_fft(self, window_size: float):
		# filtered_data = self.visible_filtered_data()
		# length = pow(2, utils.closest_power_of_two(filtered_data.shape[0]))
		# frequencies = np.linspace(0, BoardShim.get_sampling_rate(BOARD_ID) / 2, int(length / 2 + 1))
		# return frequencies, DataFilter.perform_fft(filtered_data[:length], WindowFunctions.NO_WINDOW.value)
		return utils.FeatureExtractor(self.visible_filtered_data(), global_config.SAMPLING_RATE).fft(window_size)
예제 #4
0
import cv2


def processHog(img_path, pixels_per_cell=(32, 32), cells_per_block=(1, 1)):
    final_path = utils.adress_file(img_path, "Hog")

    # http://scikit-image.org/docs/dev/api/skimage.feature.html#skimage.feature.hog
    img = cv2.imread(img_path)
    im_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    fd = hog(im_gray,
             block_norm='L2-Hys',
             cells_per_block=cells_per_block,
             pixels_per_cell=pixels_per_cell)
    # Calculate the histogram
    x = itemfreq(fd.ravel())
    # Normalize the histogram
    hist = x[:, 1] / sum(x[:, 1])

    with open(final_path, 'w+') as f:
        for v in hist:
            f.write("%.8f " % (v))
        f.write("\n")


if __name__ == "__main__":
    utils.FeatureExtractor("image", processHog).run()
    #a = FeatureExtractor("image", processHog)
    #print(next(a.data_iterator))
    #processHog(next(a.data_iterator))
    #processHog(next(a.data_iterator))