使用派生的映射函数修改s?

发布于 2025-01-29 02:25:55 字数 905 浏览 3 评论 0原文

我已经多次阅读了整篇论文,并且找到了一种使所有内容都在Python中制作的方法...除此之外(第二条第C条)。他们希望我以旧钟的2.589倍的2.589倍的新最小值和旧最大的0.9倍。我该如何实现?

编辑:感谢FMW42,我现在有一个大致执行应有的代码,但是当我使用DTW值“'tuple'对象没有属性'dtype'时,它会引发错误:

hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv_img)
clahe = cv2.createCLAHE(clipLimit=2.6, tileGridSize=(3,3))
clahe_v = clahe.apply(v)
dwts = pywt.dwt(s, 'bior1.3')

smin = np.amin(dwts)
smax = np.amax(dwts)
print("smin:", smin, "smax:", smax)
sleep(2)
smin_new = 2.589 * smin
smax_new = 0.9 * smax
print("smin_new:", smin_new, "smax_new:", smax_new)
sleep(2)

magic_s = skimage.exposure.rescale_intensity(dwts, in_range=(smin,smax), out_range=(smin_new,smax_new)).astype(np.uint8)

对Google链接btw:抱歉。 (( 文章链接:[https://www.google.com/url?sa = t& rct=j&p =&q =&p =& 2F%2FCore.AC.UK%2FDownload%2FPDF%2F2228552574.PDF& usg = aovvaw15wem7_gvgvgvmvzhmhntksn] [1]

I've read this entire paper multiple times, and I've found a way to make everything in python... Except this (Article II, section C). They want me to upscale the saturation values with a new min of 2.589 times the old min, and a new max of 0.9 times the old max. How do i achieve this?

Edit: Thanks to fmw42 i now have a code that roughly does what it should, but it throws an error when i use my dtw value "'tuple' object has no attribute 'dtype'" My code:

hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv_img)
clahe = cv2.createCLAHE(clipLimit=2.6, tileGridSize=(3,3))
clahe_v = clahe.apply(v)
dwts = pywt.dwt(s, 'bior1.3')

smin = np.amin(dwts)
smax = np.amax(dwts)
print("smin:", smin, "smax:", smax)
sleep(2)
smin_new = 2.589 * smin
smax_new = 0.9 * smax
print("smin_new:", smin_new, "smax_new:", smax_new)
sleep(2)

magic_s = skimage.exposure.rescale_intensity(dwts, in_range=(smin,smax), out_range=(smin_new,smax_new)).astype(np.uint8)

sorry for the google link btw :(
Article link: [https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&ved=2ahUKEwjx2_Cay9z3AhWDyYsKHdeFCn8QFnoECAoQAQ&url=https%3A%2F%2Fcore.ac.uk%2Fdownload%2Fpdf%2F228552574.pdf&usg=AOvVaw15wEM7_gVgvmVZhmHNTksN][1]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感性不性感 2025-02-05 02:25:55

在Python/opencv/numpy/spimage中,您可以使用np.amin()和np.amax()获取图像中的最小值和最大值。然后,从“旧最小的2.589倍的2.589倍”中计算新的最小值,而新的最大最高为0.9倍旧的最大值”。然后,使用skimage.spure.Rescale_intsentys()进行从输入值到新输出值的处理。

这是一个示例,使用旧的最小值和0.5时间的5倍,以使更改更明显。

输入:

“

import cv2
import numpy as np
import skimage.exposure

# read image
img = cv2.imread("lena.png")

# convert bgr to hsv
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

# extract channels
h,s,v = cv2.split(hsv)

# get min and max of saturation channel
smin = np.amin(s)
smax = np.amax(s)
print("smin:", smin, "smax:", smax)

# compute new saturation values
#smin_new = 2.589 * smin
#smax_new = 0.9 * smax
smin_new = 5 * smin
smax_new = 0.5 * smax
print("smin_new:", smin_new, "smax_new:", smax_new)

# modify saturation
s_new = skimage.exposure.rescale_intensity(s, in_range=(smin,smax), out_range=(smin_new,smax_new)).astype(np.uint8)

# merge hsv channels
hsv_new = cv2.merge([h,s_new,v])

# convert hsv to bgr
result = cv2.cvtColor(hsv_new, cv2.COLOR_HSV2BGR)

# save result
cv2.imwrite('lena_modified_saturation.png', result)

cv2.imshow('saturation', s)
cv2.imshow('saturation_modified', s_new)
cv2.imshow('result', result)
cv2.imshow('result', result)
cv2.waitKey(0)
cv2.destroyAllWindows()

计算:

Smin:10 Smax:255
smin_new:50 smax_new:127.5

结果:

”在此处输入图像说明”

In Python/OpenCV/Numpy/Skimage, you can use np.amin() and np.amax() to get the min and max values in the image. Then compute the new min and max from your " 2.589 times the old min, and a new max of 0.9 times the old max" in Python simple math. Then use skimage.exposure.rescale_intensity() to do the processing from input values to new output values.

Here is an example using 5 times the old min and 0.5 time the old max so that the change is more visible.

Input:

enter image description here

import cv2
import numpy as np
import skimage.exposure

# read image
img = cv2.imread("lena.png")

# convert bgr to hsv
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

# extract channels
h,s,v = cv2.split(hsv)

# get min and max of saturation channel
smin = np.amin(s)
smax = np.amax(s)
print("smin:", smin, "smax:", smax)

# compute new saturation values
#smin_new = 2.589 * smin
#smax_new = 0.9 * smax
smin_new = 5 * smin
smax_new = 0.5 * smax
print("smin_new:", smin_new, "smax_new:", smax_new)

# modify saturation
s_new = skimage.exposure.rescale_intensity(s, in_range=(smin,smax), out_range=(smin_new,smax_new)).astype(np.uint8)

# merge hsv channels
hsv_new = cv2.merge([h,s_new,v])

# convert hsv to bgr
result = cv2.cvtColor(hsv_new, cv2.COLOR_HSV2BGR)

# save result
cv2.imwrite('lena_modified_saturation.png', result)

cv2.imshow('saturation', s)
cv2.imshow('saturation_modified', s_new)
cv2.imshow('result', result)
cv2.imshow('result', result)
cv2.waitKey(0)
cv2.destroyAllWindows()

Calculations:

smin: 10 smax: 255
smin_new: 50 smax_new: 127.5

Result:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文