Last active
December 18, 2018 08:23
-
-
Save p-geon/ca753ca6b858f411efde940cfaf0b763 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# resize | |
from skimage.io import imread, imsave | |
from skimage.transform import resize | |
x = imread("X.png") | |
x2 = resize(x, (128, 128)) | |
imsave("resize.png", x2) | |
# overlay | |
from skimage.io import imread, imsave | |
from skimage.transform import resize | |
X, Y = 1024, 1024 | |
SIZE = (Y, X) | |
x1, x2 = imread("x1.png"), imread("x2.png") | |
x1, x2 = resize(x1, SIZE), resize(x2, SIZE) | |
x = (x1 + x2) / 2.0 | |
imsave("halfhalf.png", x) | |
# compare 2 images | |
import numpy as np | |
from skimage.io import imread, imsave | |
from skimage.transform import resize | |
x1 = imread("x1.png") | |
x2 = imread("x2.png") | |
conc = np.concatenate([x1, x2], axis=1) | |
imsave("concat.png", conc) | |
# edge filter | |
import cv2 | |
from skimage.io import imread, imsave | |
x = imread("x.jpg") | |
x2 = cv2.GaussianBlur(x, (9,9),0) | |
edges = cv2.Canny(x2,100,200) | |
imsave("save.png", edges) | |
# CornerHarris | |
from matplotlib import pyplot as plt | |
from skimage.io import imread, imsave | |
from skimage.feature import corner_harris, corner_subpix, corner_peaks | |
x = imread("x1.jpg", as_grey=True) | |
coords = corner_peaks(corner_harris(x), min_distance=5) | |
coords_subpix = corner_subpix(x, coords, window_size=13) | |
fig, ax = plt.subplots() | |
ax.imshow(x, interpolation='nearest', cmap=plt.cm.gray) | |
ax.plot(coords[:, 1], coords[:, 0], '.b', markersize=3) | |
ax.plot(coords_subpix[:, 1], coords_subpix[:, 0], '+r', markersize=15) | |
plt.show() | |
plt.close() | |
# 製本 | |
import numpy as np | |
from tqdm import tqdm | |
from skimage.io import imread, imsave | |
from skimage.transform import resize | |
for i in tqdm([26]): | |
file1 = i | |
file2 = i+1 | |
outname = f"m{file1}-{file2}" | |
x1 = imread(f"{file1}.png").astype(np.float32)/255.0 | |
x2 = imread(f"{file2}.png").astype(np.float32)/255.0 | |
if(len(x1.shape) == 3): | |
x1 = np.mean(x1[:,:,0:3], axis=2) | |
if(len(x2.shape) == 3): | |
x2 = np.mean(x2[:,:,0:3], axis=2) | |
conc = np.concatenate([x2, x1], axis=1) | |
imsave(f"./merged/{outname}.png", conc) | |
# フォルダをまとめてリサイズ | |
import glob | |
from skimage import io | |
from skimage.transform import resize | |
filelist = glob.glob("./dir_name/*.*") | |
for i, filename in enumerate(filelist): | |
print(filename) | |
img = io.imread(filename) | |
img = resize(img, (400, 400)) | |
img = io.imsave(f"./resized/{i:02d}.png", img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment