Skip to content

Instantly share code, notes, and snippets.

@UnaNancyOwen
Last active October 15, 2021 07:44
Show Gist options
  • Save UnaNancyOwen/ca10ae532a1554ae8caa8bd93662c21b to your computer and use it in GitHub Desktop.
Save UnaNancyOwen/ca10ae532a1554ae8caa8bd93662c21b to your computer and use it in GitHub Desktop.
convert to matrix color
import os
import numpy as np
import cv2 as cv
def main():
# 画像を読み込む
directory = os.path.dirname(__file__)
image = cv.imread(os.path.join(directory, "image.jpg"))
if image is None:
exit()
# マトリックス風カラー変換
# https://twitter.com/iquilezles/status/1440847977560494084
image = image.astype(np.float32) / 255.0
image = image ** (3.0 / 2.0, 4.0 / 5.0, 3.0 / 2.0)
image = (image * 255.0).astype(np.uint8)
# 画像を表示する
cv.imshow("matrix color", image)
cv.waitKey(0)
cv.destroyAllWindows()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment