Ask Your Question
0

How to make an image more vibrant in colour using OpenCV?

asked 2018-06-08 02:04:56 -0600

Santhosh1 gravatar image

updated 2018-06-11 01:52:43 -0600

I need to enhance few of the images before processing them. I need to enhance their colour.

I found a post online that shows how to determine how colour an image actually is.

Computing image “colorfulness” with OpenCV and Python

Code

def image_colorfulness(image):
    # split the image into its respective RGB components
    (B, G, R) = cv2.split(image.astype("float"))

    # compute rg = R - G
    rg = np.absolute(R - G)

    # compute yb = 0.5 * (R + G) - B
    yb = np.absolute(0.5 * (R + G) - B)

    # compute the mean and standard deviation of both `rg` and `yb`
    (rbMean, rbStd) = (np.mean(rg), np.std(rg))
    (ybMean, ybStd) = (np.mean(yb), np.std(yb))

    # combine the mean and standard deviations
    stdRoot = np.sqrt((rbStd ** 2) + (ybStd ** 2))
    meanRoot = np.sqrt((rbMean ** 2) + (ybMean ** 2))

    # derive the "colorfulness" metric and return it
    return stdRoot + (0.3 * meanRoot)

For my application the threshold value seems to be 24.00 lesser than this I need to enhance the colour for my application to work properly

I used Gimp tool to enhance the colour

image description

Reduce curve for the colour to be more enhanced

image description

How can I enhance colour of an image in a similar manner using OpenCV?

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
0

answered 2018-06-08 05:02:52 -0600

Santhosh1 gravatar image

Found this link how to enhance the red, green and blue color within an image? altering the saturation channel of the HSV colour space

I even need to reduce the brightness so I even had to alter the value channel of the HSV colourspace

Code

hsvImg = cv2.cvtColor(image,cv2.COLOR_BGR2HSV)

#multiple by a factor to change the saturation
hsvImg[...,1] = hsvImg[...,1]*1.4

#multiple by a factor of less than 1 to reduce the brightness 
hsvImg[...,2] = hsvImg[...,2]*0.6

image=cv2.cvtColor(hsvImg,cv2.COLOR_HSV2BGR)
edit flag offensive delete link more
0

answered 2018-06-08 06:34:58 -0600

gimp is open source,and i get some color from it before

.... //enhance the color

    Mat Img_out(temp.size(), CV_32FC3);  
    temp.convertTo(Img_out, CV_32FC3);  
    Mat Img_in(temp.size(), CV_32FC3);  
    temp.convertTo(Img_in, CV_32FC3);  
    // define the iterator of the input image  
    MatIterator_<Vec3f> inp_begin, inp_end;  
    inp_begin=Img_in.begin<Vec3f>();  
    inp_end =Img_in.end<Vec3f>();  
    // define the iterator of the output image  
    MatIterator_<Vec3f> out_begin, out_end;  
    out_begin=Img_out.begin<Vec3f>();  
    out_end =Img_out.end<Vec3f>();  
    // increment (-100.0, 100.0)  
    float Increment=50.0/100.0;   //saturation adjust
    float delta=0;  
    float minVal, maxVal;  
    float t1, t2, t3;  
    float L,S;  
    float alpha;  
    for(; inp_begin!=inp_end; inp_begin++, out_begin++)  
    {  
        t1=(*inp_begin)[0];  
        t2=(*inp_begin)[1];  
        t3=(*inp_begin)[2];  
        minVal=std::min(std::min(t1,t2),t3);  
        maxVal=std::max(std::max(t1,t2),t3);  
        delta=(maxVal-minVal)/255.0;  
        L=0.5*(maxVal+minVal)/255.0;  
        S=std::max(0.5*delta/L, 0.5*delta/(1-L));  
        if (Increment>0)  
        {  
            alpha=max(S, 1-Increment);  
            alpha=1.0/alpha-1;  
            (*out_begin)[0]=(*inp_begin)[0]+((*inp_begin)[0]-L*255.0)*alpha;  
            (*out_begin)[1]=(*inp_begin)[1]+((*inp_begin)[1]-L*255.0)*alpha;  
            (*out_begin)[2]=(*inp_begin)[2]+((*inp_begin)[2]-L*255.0)*alpha;  
        }  
        else  
        {  
            alpha=Increment;  
            (*out_begin)[0]=L*255.0+((*inp_begin)[0]-L*255.0)*(1+alpha);  
            (*out_begin)[1]=L*255.0+((*inp_begin)[1]-L*255.0)*(1+alpha);  
            (*out_begin)[2]=L*255.0+((*inp_begin)[2]-L*255.0)*(1+alpha);  
        }  
    }  
    Img_out /=255;
    Img_out.convertTo(matDst,CV_8UC3,255);

the reuslt is sth like this: image description

may it help you.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-06-08 02:04:56 -0600

Seen: 19,616 times

Last updated: Jun 11 '18