Converting pixels to coordinates in a image in Julia

  Kiến thức lập trình

I have a heatmap, and I have the coordinates for all four corners of the image. I am using linear interpolation to find out the pixel locations for newer coordinates like so:

corner_coords = [
    [-118.9883423 34.8782616],  # top-left
    [-119.4855042 34.2534752],  # bottom-left
    [-118.7960052 33.7048225],  # bottom-right
    [-118.2988434 34.3296089]   # top-right

n_rows, n_cols = size(normalized_band)
lon_min, lat_min = corner_coords[2][1], corner_coords[2][2]
lon_max, lat_max = corner_coords[3][1], corner_coords[1][2]

lon_per_pixel = abs((lon_max - lon_min) / n_cols)
lat_per_pixel = abs((lat_max - lat_min) / n_rows)

function coord_to_pixel(lon, lat, lon_min, lat_min, lon_per_pixel, lat_per_pixel)
    x_pixel = abs(lon - lon_min) / lon_per_pixel
    y_pixel = abs(lat - lat_min) / lat_per_pixel
    return round(Int, x_pixel), round(Int, y_pixel)

However, for some reason, when I plot a new coordinate or even the corner coordinates, the plot generated is incorrect and has a significant error.

The map I have is not distorted since the distance of the opposite edges is the same.