Skip to content

Instantly share code, notes, and snippets.

@eqs
Created November 14, 2015 14:42
Show Gist options
  • Save eqs/8bdbd2fee49f536942ea to your computer and use it in GitHub Desktop.
Save eqs/8bdbd2fee49f536942ea to your computer and use it in GitHub Desktop.
アップル加工
# -*- coding: utf-8 -*-
"""
Created on 2015/11/14 22:40:07
アップル加工
@author: eqs
"""
import sys
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as pcl
import scipy.ndimage as sim
def con(x):
X = np.int32(x * 360)
if 0 <= X <= 30 or 330 <= X <= 360:
# 赤色っぽい部分はそのまま
return x
else:
# 赤色っぽくない部分は変な値にしておく(あとで彩度を0にするための目印)
return -1
im = sim.imread('jaga.jpg')
im = im / 255.0 # normalize
im_hsv = pcl.rgb_to_hsv(im)
f = np.vectorize(con)
im_hsv[:, :, 0] = f(im_hsv[:, :, 0])
im_hsv[:, :, 1][im_hsv[:, :, 0] != -1] *= 1.0
im_hsv[:, :, 1][im_hsv[:, :, 0] == -1] = 0
im_rgb = pcl.hsv_to_rgb(im_hsv)
plt.subplot(121), plt.imshow(im), plt.title('source image')
plt.subplot(122), plt.imshow(im_rgb), plt.title('converted image')
plt.show()
@eqs
Copy link
Author

eqs commented Nov 14, 2015

source image :

converted image :

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment