giovedì 1 giugno 2023

Match Histogram

Un esempio per normalizzare l'istogramma tra due immagini riprese a differente orari con ovvie differenze di illuminazione mediante la funzione match_histogram di Scikit (attenzione che nelle versioni precedenti la funzione era definita in modo differente per i parametri)


Immagine corretta. Si usa la prima come reference e la seconda come immagine da correggere


 Questi gli istogrammi prima e dopo l'algoritmo


from skimage import exposure
import matplotlib.pyplot as plt
import argparse
import cv2
ap = argparse.ArgumentParser()
ap.add_argument("-s", "--source", required=True,
help="path to the input source image")
ap.add_argument("-r", "--reference", required=True,
help="path to the input reference image")
args = vars(ap.parse_args())

print("[INFO] loading source and reference images...")
src = cv2.imread(args["source"])
ref = cv2.imread(args["reference"])
print("[INFO] performing histogram matching...")
multi = True if src.shape[-1] > 1 else False
matched = exposure.match_histograms(src, ref, channel_axis=-1)
cv2.imshow("Source", src)
cv2.imshow("Reference", ref)
cv2.imshow("Matched", matched)
cv2.imwrite("matched.jpg",matched)
cv2.waitKey(0)

(fig, axs) = plt.subplots(nrows=3, ncols=3, figsize=(8, 8))
for (i, image) in enumerate((src, ref, matched)):
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
for (j, color) in enumerate(("red", "green", "blue")):
(hist, bins) = exposure.histogram(image[..., j],
source_range="dtype")
axs[j, i].plot(bins, hist / hist.max())
(cdf, bins) = exposure.cumulative_distribution(image[..., j])
axs[j, i].plot(bins, cdf)
axs[j, 0].set_ylabel(color)

axs[0, 0].set_title("Source")
axs[0, 1].set_title("Reference")
axs[0, 2].set_title("Matched")
plt.tight_layout()
plt.savefig("grafico.png")

 

Nessun commento:

Posta un commento

ESP32-2432S028R e LVGL

La scheda ESP32-2432S028R monta un Esp Dev Module con uno schermo TFT a driver ILI9341 di 320x240 pixels 16 bit colore.Il sito di riferiment...