Я хотел бы перенести обработку изображений из Image J (Фиджи) в Python.В изображении J я разделил изображение на HSB, а затем использовал автопорог Moments на канале B.На Python я хочу иметь значение порога t, с которого выполняется сегментация.Поскольку я не смог найти никакой помощи или фрагмента кода по этому вопросу, я здесь.Из статьи «Сохранение момента: новый подход, Цай» ( здесь ), я сделал это:
import numpy as np
import cv2
import skimage
from skimage import io
img = io.imread("C:\\Users\\Image.tif")
hsv_img = cv2.cvtColor(filt_img, cv2.COLOR_RGB2HSV)
H, S, B = cv2.split(img) # spliting the image into HSB
B_histo = skimage.exposure.histogram (B) # making the histogram
pix_sum = B.shape[0]*B.shape[1] # calculating the sum of the pixels
#from the paper, calculating the 4 first odrers m0, m1, m2, m3 to get to p0. The name of the further variables stems from the paper.
pj = B_histo[0] / pix_sum
pj_z1 = np.power(B_histo[1], 1) * pj
pj_z2 = np.power(B_histo[1], 2) * pj
pj_z3 = np.power(B_histo[1], 3) * pj
m0 = np.sum(pj)
m1 = np.sum(pj_z1)
m2 = np.sum(pj_z2)
m3 = np.sum(pj_z3)
cd = (m0*m2) - (m1*m1)
c0 = ((-m2*m2) - (-m3*m1))/cd
c1 = ((m0*-m3) - (m1*-m2))/cd
z0 = 0.5 *(-c1 - (np.power(np.power(c1, 2) - 4*c0, 1/2)))
z1 = 0.5 *(-c1 + (np.power(np.power(c1, 2) - 4*c0, 1/2)))
pd = z1 - z0
p0 = (z1 - m1) / pd # p0 should be the percentage of the pixels to which the value 0 is attributed
# using cumulative histogram and comparing it to a target value by calculating the difference. When the difference is the lowest, the index indicates the value of the threshold t
cum_pix = np.cumsum(B_histo[0])
target_value = p0 * pix_sum
#td = cum_pix
diff = [abs(i - target_value) for i in cum_pix]
cum_pix[1]
diff[0]
t = [abs(i - target_value) for i in cum_pix].index(np.min(diff))
print(t)
Извините за грязный код.В любом случае, значение, которое я вычисляю на Python, отличается от значения на изображении J. Знаете ли вы, откуда может возникнуть проблема?Или в Python есть функция, которая может получить значение автопорога момента?Я очень ценю советы или подсказки, чтобы копать, спасибо