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)


``
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值