openISP icon indicating copy to clipboard operation
openISP copied to clipboard

what stardard do you use in the color space conversion?

Open wjtan99 opened this issue 2 years ago • 3 comments

The conversion matrix is [0.257 0.504 0.098 16; -0.148 -0.291 0.439 128; 0.439 -0.368 -0.071 128]. What is this standard of your implementation? In addition, have you implemented lens shading correction? Thank you.

wjtan99 avatar Dec 08 '21 17:12 wjtan99

Never mind, I found it in your document. I did not find the LSC in your code. Did you implement it?

wjtan99 avatar Dec 08 '21 18:12 wjtan99

Never mind, I found it in your document. I did not find the LSC in your code. Did you implement it?

Not yet, LSC was realized by some approximation functions. Didn't include it.

cruxopen avatar Mar 05 '22 14:03 cruxopen

Never mind, I found it in your document. I did not find the LSC in your code. Did you implement it?

Not yet, LSC was realized by some approximation functions. Didn't include it.

Should we append the functionality of LSC such like this project?

class lens_shading_correction:
    def __init__(self, data, name="lens_shading_correction"):
        # convert to float32 in case it was not
        self.data = np.float32(data)
        self.name = name

    def flat_field_compensation(self, dark_current_image, flat_field_image):
        # dark_current_image:
        #       is captured from the camera with cap on
        #       and fully dark condition, several images captured and
        #       temporally averaged
        # flat_field_image:
        #       is found by capturing an image of a flat field test chart
        #       with certain lighting condition
        # Note: flat_field_compensation is memory intensive procedure because
        #       both the dark_current_image and flat_field_image need to be
        #       saved in memory beforehand
        print("----------------------------------------------------")
        print("Running lens shading correction with flat field compensation...")

        # convert to float32 in case it was not
        dark_current_image = np.float32(dark_current_image)
        flat_field_image = np.float32(flat_field_image)
        temp = flat_field_image - dark_current_image
        return np.average(temp) * np.divide((self.data - dark_current_image), temp)

    def approximate_mathematical_compensation(self, params, clip_min=0, clip_max=65535):
        # parms:
        #       parameters of a parabolic model y = a*(x-b)^2 + c
        #       For example, params = [0.01759, -28.37, -13.36]
        # Note: approximate_mathematical_compensation require less memory
        print("----------------------------------------------------")
        print("Running lens shading correction with approximate mathematical compensation...")
        width, height = utility.helpers(self.data).get_width_height()

        center_pixel_pos = [height/2, width/2]
        max_distance = utility.distance_euclid(center_pixel_pos, [height, width])

        # allocate memory for output
        temp = np.empty((height, width), dtype=np.float32)

        for i in range(0, height):
            for j in range(0, width):
                distance = utility.distance_euclid(center_pixel_pos, [i, j]) / max_distance
                # parabolic model
                gain = params[0] * (distance - params[1])**2 + params[2]
                temp[i, j] = self.data[i, j] * gain

        temp = np.clip(temp, clip_min, clip_max)
        return temp

    def __str__(self):
        return "lens shading correction. There are two methods: " + \
                "\n (1) flat_field_compensation: requires dark_current_image and flat_field_image" + \
                "\n (2) approximate_mathematical_compensation:"

Kuo-TingKai avatar Jan 10 '23 13:01 Kuo-TingKai