이미지가 마스크 처리 된 배열로 나타납니다. 이미지는 전경과 배경으로 구성되어 있습니다. 배경에 관심이 없으므로 가려졌습니다. 대비가 좋지 않은 이미지이고 전경에서 대비를 높이고 싶습니다. skimage.exposure.equalize_hist
마스크 된 배열을 통해 skimage.equalize_hist를 수행하는 동안 오류가 발생했습니다.
equalize_hist 함수가 마스크 된 데이터를 무시하기 위해 명명 된 매개 변수 mask
을 사용하는 것으로 나타났습니다. 이
import numpy as np
import skimage.exposure as ske
import matplotlib.pyplot as plt
# doesn't really exist
from proprietary import openImage, findForeground
imagePath = "...." # path to the image file
# image format is proprietary, so we have a custom function open it for us
# it returns a regular numpy uint16 2d array
# print(type(img), img.dtype, img.shape) shows
# `
# <class 'numpy.ndarray'> float64 (2688, 1151)
# `
img = openImage(imagePath)
foreground = findForeground(img) # this function sets all background pixels to white
# 65535 == white for a uint16 array
masked_img = np.ma.masked_where(foreground==65535, foreground)
# plotting this `masked_img` using plt.imshow works perfectly, the background is completely white
# and the foreground is shown as it is supposed to
# this goes wrong
mask = np.ma.getmask(masked_img)
equalized = ske.equalize_hist(masked_img, mask=mask)
ske.equalize_hist
호출이 오류가 발생합니다 같은
내 코드를보고, 그 이유를 확실 해요.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-e2b4f8e60ef9> in <module>()
37 print(type(mask))
38 print(mask)
---> 39 equalized = ske.equalize_hist(fg, mask=mask)
40 plt.imshow(equalized, cmap=cmap)
41 plt.set_title("Equalized histogram with colormap {cmap}".format(cmap=cmap))
C:\Users\myuser\AppData\Local\Continuum\Anaconda3\lib\site-packages\skimage\exposure\exposure.py in equalize_hist(image, nbins, mask)
165 cdf, bin_centers = cumulative_distribution(image[mask], nbins)
166 else:
--> 167 cdf, bin_centers = cumulative_distribution(image, nbins)
168 out = np.interp(image.flat, bin_centers, cdf)
169 return out.reshape(image.shape)
C:\Users\myuser\AppData\Local\Continuum\Anaconda3\lib\site-packages\skimage\exposure\exposure.py in cumulative_distribution(image, nbins)
125 True
126 """
--> 127 hist, bin_centers = histogram(image, nbins)
128 img_cdf = hist.cumsum()
129 img_cdf = img_cdf/float(img_cdf[-1])
C:\Users\myuser\AppData\Local\Continuum\Anaconda3\lib\site-packages\skimage\exposure\exposure.py in histogram(image, nbins)
86 return hist[idx:], bin_centers[idx:]
87 else:
---> 88 hist, bin_edges = np.histogram(image.flat, bins=nbins)
89 bin_centers = (bin_edges[:-1] + bin_edges[1:])/2.
90 return hist, bin_centers
C:\Users\myuser\AppData\Local\Continuum\Anaconda3\lib\site-packages\numpy\lib\function_base.py in histogram(a, bins, range, normed, weights, density)
495 mn, mx = 0.0, 1.0
496 else:
--> 497 mn, mx = a.min() + 0.0, a.max() + 0.0
498 else:
499 mn, mx = [mi + 0.0 for mi in range]
TypeError: unsupported operand type(s) for +: 'MaskedIterator' and 'float'
누구에게 이런 일이 발생했는지 알 수 있습니까? 나는 잃어 버렸다.
일반적으로 'numpy'및 제 3 자 코드는 마스크 된 배열을 특별한 방법으로 처리하지 않습니다. 그들은 단지'data' 속성을 사용합니다. 'ma' 메소드를 위임하는'np.ma ...'함수 나 함수를 사용해야합니다. 하지만'equalize_hist (masked_img.data, mask = mask)'를 시도해 보셨습니까? – hpaulj
또한,'foreground = 65535'는 아마도'foreground == 65535'이어야합니다. –
@MadPhysicist True, 저는 원래 코드에서 double equals를 가졌지 만 여기서는 그렇지 않습니다. 고쳤다. – Azeirah