当前位置:网站首页>Undistorted resize using pil
Undistorted resize using pil
2022-06-30 16:48:00 【Wutiande, young Xia】
Make a deformation free resize
Code
import os
from PIL import Image
import math
def resize_pad(image,target_size):
w,h = image.size
minx = min(w,h)
if minx == h:
# w You can zoom to 224
# h Conduct padding
new_h = int(h * (target_size/w))
image = image.resize((target_size,new_h),Image.Resampling.BICUBIC)
# Generate one targe_size Size chart
aimage = Image.new('RGB',(target_size,target_size),(127,127,127))
# Calculate the size to be pasted on it
psize_up = (target_size - new_h)//2
# Paste the scaled image
aimage.paste(image,(0,psize_up))
aimage.show()
else:
# minx==w
# h You can zoom to 224
# w Conduct padding
new_w = int(w * (target_size/h))
image = image.resize((new_w,target_size),Image.Resampling.BICUBIC)
# Generate one targe_size Size chart
aimage = Image.new('RGB',(target_size,target_size),(127,127,127))
# Calculate the size to be pasted on the left
psize_left = (target_size - new_w)//2
# Paste the scaled image
aimage.paste(image,(psize_left,0))
aimage.show()
if __name__ == '__main__':
image_path = "E:/my_datasets/keypoint_2d/hand_keypoint/hand_keypoint/val/JPEGImages/1577.png"
image = Image.open(image_path).convert('RGB')
ori = image.resize((224,224))
ori.show()
resize_pad(image,target_size=224)
边栏推荐
- 7 月 2 日邀你来TD Hero 线上发布会
- 15年做糊21款硬件,谷歌到底栽在哪儿?
- More dragon lizard self-developed features! Production available Anolis OS 8.6 officially released
- Under the pressure of technology, you can quickly get started with eth smart contract development, which will take you into the ETH world
- 搬运两个负载均衡的笔记,日后省的找
- 中航无人机科创板上市:市值385亿 拳头产品是翼龙无人机
- How to get the preferential activities for stock account opening? Is online account opening safe?
- Hologres shared cluster helps Taobao subscribe to the extreme refined operation
- CMakeLists 基础
- 中国传奇教授李泽湘,正在批量制造独角兽
猜你喜欢
新茶饮“死去活来”,供应商却“盆满钵满”?
ArcMap operation series: 80 plane to latitude and longitude 84
MySQL transaction / lock / log summary
Rongsheng biology rushes to the scientific innovation board: it plans to raise 1.25 billion yuan, with an annual revenue of 260million yuan
JS Es5 can also create constants?
抖快B为啥做不好综艺
备战数学建模33-灰色预测模型2
RT-Thread 堆區大小設置
CVPR 2022 - Tesla AI proposed: generalized pedestrian re recognition based on graph sampling depth metric learning
MC Instruction Decoder
随机推荐
ArcMap operation series: 80 plane to latitude and longitude 84
Symantec electronic sprint technology innovation board: Tan Jian, the actual controller, is an American who plans to raise 620million yuan
Anaconda下安装Jupyter notebook
Arcmap操作系列:80平面转经纬度84
[machine learning] K-means clustering analysis
MC Instruction Decoder
赛芯电子冲刺科创板:拟募资6.2亿 实控人谭健为美国籍
新茶饮“死去活来”,供应商却“盆满钵满”?
Rongsheng biology rushes to the scientific innovation board: it plans to raise 1.25 billion yuan, with an annual revenue of 260million yuan
腾讯二面:@Bean 与 @Component 用在同一个类上,会怎么样?
【Verilog基础】关于Clock信号的一些概念总结(clock setup/hold、clock tree、clock skew、clock latency、clock transition..)
Bidding announcement: Tianjin housing provident fund management center database all-in-one machine and database software project (budget: 6.45 million)
Niuke.com: minimum cost of climbing stairs
Niuke network: longest continuous subarray with positive product
halcon知识:矩阵专题【02】
Asp. NETCORE uses cache and AOP to prevent repeated commit
备战数学建模35-时间序列预测模型
备战数学建模34-BP神经网络预测2
Distributed machine learning: model average Ma and elastic average easgd (pyspark)
搬运两个负载均衡的笔记,日后省的找