Ask Your Question
1

remove white reflection from image

asked 2018-06-29 10:28:22 -0600

Peter12 gravatar image

Hi there, I am getting these pictures from my camera. Ususally there are white reflections on the pictures during the day. Is there any option how to remove reflections from the image "on the fly" (when camera output is viewed)?

P.S. it can be in various position during the day and it should be nice to have nice image without these reflections.

image description image description

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2018-06-29 17:25:35 -0600

sjhalayka gravatar image

updated 2018-06-30 10:19:21 -0600

One way would be to alter the saturation.

In C++:

#include <opencv2/opencv.hpp>
using namespace cv;
#pragma comment(lib, "opencv_world340.lib")

#include <iostream>
using namespace std;

int main(void)
{
    Mat frame = imread("rainbow.jpg");

    if (frame.empty())
    {
        cout << "Could not read image file." << endl;
        return 1;
    }

    Mat hsv;
    cvtColor(frame, hsv, CV_BGR2HSV);

    for (int j = 0; j < frame.rows; j++)
        for (int i = 0; i < frame.cols; i++)
            hsv.at<Vec3b>(j, i)[1] = 255;

    cvtColor(hsv, frame, CV_HSV2BGR);

    imshow("frame", frame);
    waitKey(0);

    return 0;
}

In Python:

import cv2
import numpy

frame = cv2.imread('rainbow.jpg')

if frame is None:
    print('Error loading image')
    exit()    

rows = frame.shape[0]
cols = frame.shape[1]

hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV);

for i in range(0, cols):
    for j in range(0, rows):
        hsv[j, i][1] = 255;

frame = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR);

cv2.imshow("Frame", frame)
cv2.waitKey(0)
edit flag offensive delete link more

Comments

thank you. I am going to analyze your code and I will try to rewrite it for python2.7 and opencv2

Peter12 gravatar imagePeter12 ( 2018-06-30 05:37:52 -0600 )edit

@Peter12 -- I updated the answer to include the Python code. Sorry that I missed your python tag. :)

sjhalayka gravatar imagesjhalayka ( 2018-06-30 10:18:23 -0600 )edit

@Peter12 — you may want to calculate the average saturation value for the entire image, and use that value to set the saturation.

sjhalayka gravatar imagesjhalayka ( 2018-06-30 12:46:45 -0600 )edit

@sjhalayka wow, it looks cool. thank you very much! I am going to experiment with it a bit.

Peter12 gravatar imagePeter12 ( 2018-07-02 02:01:10 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2018-06-29 10:28:22 -0600

Seen: 5,280 times

Last updated: Jun 30 '18