setting tp1
This commit is contained in:
parent
a893c030fd
commit
07e47d5b09
@ -4,4 +4,4 @@
|
||||
|
||||
## Practicals
|
||||
|
||||
1. [Color Transfer via Discrete Optimal Transport using the sliced approach](https://codimd.math.cnrs.fr/s/2eRBqV9zl)
|
||||
1. [Color Transfer via Discrete Optimal Transport using the sliced approach](https://codimd.math.cnrs.fr/s/s_rh7X9wF), [Material](https://github.com/dcoeurjo/CGDI-Practicals/tree/main/1-SlicedOptimalTransport)
|
||||
|
3
misc/README.md
Normal file
3
misc/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Extra tools
|
||||
|
||||
* `computeHistogram.py`: compute and the three RGB histograms from an image.
|
49
misc/computeHistogram.py
Executable file
49
misc/computeHistogram.py
Executable file
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
# import the necessary packages
|
||||
from matplotlib import pyplot as plt
|
||||
import numpy as np
|
||||
import argparse
|
||||
import cv2
|
||||
|
||||
# construct the argument parser and parse the arguments
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("-i", "--image", required = True, help = "Path to the image")
|
||||
ap.add_argument("-o", "--outputhist", required = True, help = "Path to the histogram image")
|
||||
args = vars(ap.parse_args())
|
||||
|
||||
# load the image and show it
|
||||
image = cv2.imread(args["image"])
|
||||
cv2.imshow("image", image)
|
||||
|
||||
|
||||
# grab the image channels, initialize the tuple of colors,
|
||||
# the figure and the flattened feature vector
|
||||
chans = cv2.split(image)
|
||||
colors = ("b", "g", "r")
|
||||
plt.figure()
|
||||
plt.title("")
|
||||
plt.xlabel("Bins")
|
||||
plt.ylabel("# of Pixels")
|
||||
features = []
|
||||
|
||||
# loop over the image channels
|
||||
for (chan, color) in zip(chans, colors):
|
||||
# create a histogram for the current channel and
|
||||
# concatenate the resulting histograms for each
|
||||
# channel
|
||||
hist = cv2.calcHist([chan], [0], None, [256], [0, 256])
|
||||
features.extend(hist)
|
||||
|
||||
# plot the histogram
|
||||
plt.plot(hist, color = color)
|
||||
plt.xlim([0, 256])
|
||||
|
||||
|
||||
plt.savefig(args["outputhist"])
|
||||
# here we are simply showing the dimensionality of the
|
||||
# flattened color histogram 256 bins for each channel
|
||||
# x 3 channels = 768 total values -- in practice, we would
|
||||
# normally not use 256 bins for each channel, a choice
|
||||
# between 32-96 bins are normally used, but this tends
|
||||
# to be application dependent
|
||||
print("flattened feature vector size: %d" % (np.array(features).flatten().shape))
|
Loading…
x
Reference in New Issue
Block a user