Matlab的inadjust在python中相当于什么? [英] What is the equivalent of Matlab's imadjust in python?

查看:197
本文介绍了Matlab的inadjust在python中相当于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在python中是否等效于 imadjust . equalizeHist没有给出类似的结果.

Is there an equivalent of imadjust in python. equalizeHist does not give a similar result.

推荐答案

一种解决方案是以下代码:

One solution is the following piece of code:

def imadjust(x,a,b,c,d,gamma=1):
    # Similar to imadjust in MATLAB.
    # Converts an image range from [a,b] to [c,d].
    # The Equation of a line can be used for this transformation:
    #   y=((d-c)/(b-a))*(x-a)+c
    # However, it is better to use a more generalized equation:
    #   y=((x-a)/(b-a))^gamma*(d-c)+c
    # If gamma is equal to 1, then the line equation is used.
    # When gamma is not equal to 1, then the transformation is not linear.

    y = (((x - a) / (b - a)) ** gamma) * (d - c) + c
    return y

用法示例:

Matplotlib.pyplot的imshow函数要求输入图像的范围为[0,1].以下示例显示了如何读取RGB或灰度图像,缩放图像并显示它.

Matplotlib.pyplot's imshow function requires that the range of the input image is in [0,1]. The following example shows how to read a RGB or gray-scale image, scale the image, and display it.

from PIL import Image
import matplotlib.pyplot as plt
import numpy as np

image = Image.open(fname)
arr = np.asarray(image)
arr2=imadjust(arr,arr.min(),arr.max(),0,1)

fig = plt.figure()
fig.suptitle('image')
plt.imshow(arr2)
plt.show()

这篇关于Matlab的inadjust在python中相当于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆