我想問如何使用python代碼獲取影像結果(圖示),如中所示

其中 ishade 是經過預處理的影像,std(Ishade) 是該影像的標準差
result = ndimage.median_filter(blur, size=68)
std=cv2.meanStdDev(result)
uj5u.com熱心網友回復:
我嘗試按照您發布的參考文獻中的文章以及該帖子中對原始文章的參考進行操作。但我不完全了解他們的所作所為。盡管如此,這是我的解釋(除了最初的 CLAHE)。您可以根據需要調整均值和中值濾波器大小。
輸入:

import cv2
import numpy as np
import skimage.exposure
# load image
img = cv2.imread("lena.jpg")
# convert to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Gaussian blurred gray image
mean = cv2.GaussianBlur(gray, (0,0), sigmaX=5, sigmaY=5)
# apply median filter to mean image
median = cv2.medianBlur(mean, 25)
# divide mean by median
division = cv2.divide(mean.astype(np.float64)/255, median.astype(np.float64)/255)
# get global standard deviation of division
std = np.std(division)
print(std)
# divide the division by the std and normalize to range 0 to 255 as unint8
result = np.divide(division, std)
result = skimage.exposure.rescale_intensity(result, in_range='image', out_range=(0,255)).astype(np.uint8)
# write result to disk
cv2.imwrite("lena_std_division2.jpg", result)
# display it
cv2.imshow("mean", mean)
cv2.imshow("median", median)
cv2.imshow("division", division)
cv2.imshow("result", result)
cv2.waitKey(0)
cv2.destroyAllWindows()
結果:

uj5u.com熱心網友回復:
我不確定我明白你想要什么。有不同型別的歸一化公式。
最常見的方法是從影像中減去平均值,然后除以標準差。(I-mean(I))/std(I)
但是如果你想做你的公式,I/std(I)那么它可以如下完成:
輸入:

import cv2
import numpy as np
import skimage.exposure
# load image
img = cv2.imread("lena.jpg")
# convert to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY).astype(np.float64)/255
# get local mean from blurred gray image and square it
sigma=15
mean = cv2.GaussianBlur(gray, (0,0), sigmaX=sigma, sigmaY=sigma)
mean_sq = cv2.multiply(mean,mean)
# get mean of gray image squared
gray2 = cv2.multiply(gray,gray)
mean2 = cv2.GaussianBlur(gray2, (0,0), sigmaX=sigma, sigmaY=sigma)
# get variance image from the two means
var = cv2.subtract(mean2, mean_sq)
# get the standard deviation image from the variance image
std = np.sqrt(var)
print(std.dtype, np.amax(std), np.amin(std))
# divide image by std and scale using skimage
divide = (255*cv2.divide(gray, std, scale=1)).clip(0,255).astype(np.uint8)
divide = skimage.exposure.rescale_intensity(divide, in_range='image', out_range=(0,255)).astype(np.uint8)
print(divide.dtype, np.amax(divide), np.amin(divide))
# write result to disk
cv2.imwrite("lena_std_division.jpg", divide)
# display it
cv2.imshow("std", std)
cv2.imshow("divide", divide)
cv2.waitKey(0)
cv2.destroyAllWindows()
結果(取決于 sigma 值):

我已經發布了一些示例(稱為除法歸一化)的替代公式是將影像除以其區域平均影像。I/mean(I))
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/450171.html
標籤:Python python-3.x opencv opencv3.0
