Skimage.color took too long for execution

Viewed 17

i am try to apply specific color over a person in an image. The code function what is given below is working well but it too long for color.rgb2lab as well as color.lab2rgb to execute. Can any one suggest alternate method for this same application.

def apply_color(chosen_color, image, height, width):
    b, g, r = chosen_color[0], chosen_color[1], chosen_color[2]
    val = color.rgb2lab((image / 255.)).reshape(width * height, 3)

    L, A, B = mean(val[:, 0]), mean(val[:, 1]), mean(val[:, 2])
    L1, A1, B1 = color.rgb2lab(np.array((r / 255., g / 255., b / 255.)).reshape(1, 1, 3)).reshape(3, )
    ll, aa, bb = (L1 - L) * intensity, (A1 - A) * intensity, (B1 - B) * intensity
    val[:, 0] = np.clip(val[:, 0] + ll, 0, 100)
    val[:, 1] = np.clip(val[:, 1] + aa, -127, 128)
    val[:, 2] = np.clip(val[:, 2] + bb, -127, 128)
    blush_image = color.lab2rgb(val.reshape(height, width, 3)) * 255
    return blush_image

I tried with opencv instead of skimage but it gives an error.

val = cv2.cvtColor(image/255, cv2.COLOR_RGB2LAB).reshape(width * height, 3)

the above oneline code represent the change I try to made instead of 3rd line in above method. the error what i got,

    cv2.error: OpenCV(4.6.0) /io/opencv/modules/imgproc/src/color.simd_helpers.hpp:94: error: (-2:Unspecified error) in function 'cv::impl::{anonymous}::CvtHelper<VScn, VDcn, VDepth, sizePolicy>::CvtHelper(cv::InputArray, cv::OutputArray, int) [with VScn = cv::impl::{anonymous}::Set<3, 4>; VDcn = cv::impl::{anonymous}::Set<3>; VDepth = cv::impl::{anonymous}::Set<0, 5>; cv::impl::{anonymous}::SizePolicy sizePolicy = cv::impl::<unnamed>::NONE; cv::InputArray = const cv::_InputArray&; cv::OutputArray = const cv::_OutputArray&]'
> Unsupported depth of input image:
>     'VDepth::contains(depth)'
> where
>     'depth' is 6 (CV_64F)

I hope i explained the problem well enough. Thanks in advance.

0 Answers
Related