xsnizer
xsnizer

Reputation: 1

How to Interpolate Unknown Pixel given Coordinates references?

I just used Python for computer vision. I need lots of references for pixel interpolation in images using Python.

I have an RGB image like the following. In that picture, I have a white unknown pixel. I want to interpolate the unknown pixel starting from the point (x0, y0) using the colour intensity information along the blue line. Can someone provide code samples for interpolating at point (x0, y0) with any interpolation technique? The input is a collection of coordinate colour references x,y = np.where(np.all(img == [0,0,255],axis=2)) and pixel coordinates (x0, y0). The output is pixels (x0, y0) which have been interpolated.

enter image description here

Upvotes: 0

Views: 588

Answers (1)

Oladimeji Mudele
Oladimeji Mudele

Reputation: 63

I will solve ths problem using a bunch of functions.

First for a given coordinate (x_i, y_i), I obtain the list of pixel coordinates on both sides of it within a particular window of size = window_size

i.e

def derive_adjacent_coords(coord, window_size):
    # Coord is a tuple (row, column)

    assert (window_size % 2) != 0, "Window size must be odd"
    mid_idx = (window_size - 1) / 2)

    return [(r, coord[1]) for r in range(coord[0] - mid_idx, coord[0] + mid_idx + 1)]

Then I will I extract the values that correspond to these locations in the image using the function below:

def derive_adjacent_pixels(list_of_coord_tuples, image):
    # Image is your image, list_of_coord_tuples is the output of the first function
    return [ image[*i] for i in list_of_coord_tuples]

The function above will return a list. Then I will interpolate the list:

from scipy.interpolate import interp1d
import math

def interpol(list):
    # list is the output of the derive_adjacent_pixels(list_of_coord_tuples, image) function
    x = [i for i in range len(list)]
    interpolated_list = interp1d(x, list, kind='cubic')
    return interpolated_list[int(math.floor(len(interpolated_list)/2))]

You have to interpolate each band of the image differently in this method I have shown above.

You will have to iterate these functions over your list of unknown pixels coords (list of tuples) and then individually for each band in your image.

Upvotes: 0

Related Questions