Skip to content

Adding Jit #1

Description

@8bignic8

Hey I added Jit to your Programm but i dont know how to push to your projekt its much faster, soooo. Here is the code:
requrements conda install numba

import cv2
import numpy as np
import math
from numba import jit

def RGB_TO_HSI(img):

with np.errstate(divide='ignore', invalid='ignore'):

    #Load image with 32 bit floats as variable type
    bgr = np.float32(img)/255

    #Separate color channels
    blue = bgr[:,:,0]
    green = bgr[:,:,1]
    red = bgr[:,:,2]

    #Calculate Intensity
    def calc_intensity(red, blue, green):
        return np.divide(blue + green + red, 3)

    #Calculate Saturation
    def calc_saturation(red, blue, green):
        minimum = np.minimum(np.minimum(red, green), blue)
        saturation = 1 - (3 / (red + green + blue + 0.001) * minimum)

        return saturation

    #Calculate Hue
    def calc_hue(red, blue, green):
        hue = np.copy(red)
        i = 0
        while (i <= int(blue.shape[0]) - 1):
            j = 0
            while (j <= int(blue.shape[1]) - 1):
                hue[i][j] = 0.5 * ((red[i][j] - green[i][j]) + (red[i][j] - blue[i][j])) / \
                            math.sqrt((red[i][j] - green[i][j]) ** 2 +
                                      ((red[i][j] - blue[i][j]) * (green[i][j] - blue[i][j])))
                hue[i][j] = math.acos(hue[i][j])

                if blue[i][j] <= green[i][j]:
                    hue[i][j] = hue[i][j]
                else:
                    hue[i][j] = ((360 * math.pi) / 180.0) - hue[i][j]
                j = j + 1
            i = i + 1

        return hue

        return hue

    #Merge channels into picture and return image
    jitHUE = jit()(calc_hue)
    hsi = cv2.merge((jitHUE(red, blue, green), calc_saturation(red, blue, green), calc_intensity(red, blue, green)))
    return hsi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions