python图片采样

python程序采样

import run

import numpy as np
from PIL import Image
import tensorflow as tf
import os
import cv2


"""
using the checkpoints to get result
of shadow, water and layover simultaneously 
"""
img_test_dir = 'D:\\Users\\caixingmin\\Desktop\\test1\\1\\'
img_result_dir = 'D:\\Users\\caixingmin\\Desktop\\test1\\2\\'

def Whiite_Black_Level_Pretreatment(img, Shadow, Highlight):
    if Highlight > 255:
        Highlight = 255
    if Shadow < 0:
        Shadow = 0
    if Shadow >= Highlight:
        Shadow = Highlight - 2
# 转类型
    img = np.array(img, dtype=int)
# 计算白场黑场离差
    Diff = Highlight - Shadow
# 计算系数
    coe = 255.0 / Diff
    rgbDiff = img - Shadow
    rgbDiff = np.maximum(rgbDiff, 0)
    img = rgbDiff * coe
# 四舍五入到整数
    img = np.around(img, 0)
# 变为int型
    img = img.astype(int)
    return img

for filename in os.listdir(img_test_dir):
        img_name = img_test_dir + filename
        img = cv2.imread(img_name)
        
        img_h = img.shape[0]
        img_w = img.shape[1]
        #img = img.resize((img_h//15, img_w//15), Image.ANTIALIAS)
        img1 = cv2.resize(img,(500, 500), interpolation=cv2.INTER_NEAREST)
        #img = cv2.equalizeHist(img)
        #img = Whiite_Black_Level_Pretreatment(img,0,40)
        #print(img.shape[0])
        final = os.path.join(img_result_dir, filename) 
       # print(final)
        cv2.imwrite(final,img1)


``

你可能感兴趣的:(matlab,python,opencv)