MATLAB 与 python 中裁剪图片的不同之处

在 python 中使用 PIL 包中的 Image 进行图像裁剪时,传入的四元组信息为 [left, top, right, bottom],而 MATLAB 中的 imcrop 传入的四元组为 [xmin, ymin, weight, height]。

也就是说,在 python 中传入的是矩形框左上角和右下角的坐标,而在 MATLAB 中传入的是矩形框左上角与宽、高信息。

假设 r e c t p y t h o n = [ l e f t , t o p , r i g h t , b o t t o m ] rect_{python} = [left, top, right, bottom] rectpython=[left,top,right,bottom],则 r e c t m a t l a b = [ l e f t , t o p , r i g h t − l e f t , b o t t o m − t o p ] rect_{matlab} = [left, top, right-left, bottom-top] rectmatlab=[left,top,rightleft,bottomtop]

#----------- python --------------#
from PIL import Image
image = Image.open(img_path)
cropped = image.crop(rect_python)
cropped.show()
#----------- matlab -------------#
I = imread(img_path)
I2 = imcrop(I,rect_matlab)
imshow(I2)

虽然这是一个小问题,但是也很容易被忽略。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值