Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_hist_ismonotonic(self):
im = pyvips.Image.identity()
assert im.hist_ismonotonic()
def test_identity(self):
im = pyvips.Image.identity()
assert im.width == 256
assert im.height == 1
assert im.bands == 1
assert im.format == pyvips.BandFormat.UCHAR
p = im(0, 0)
assert p[0] == 0.0
p = im(255, 0)
assert p[0] == 255.0
p = im(128, 0)
assert p[0] == 128.0
im = pyvips.Image.identity(ushort=True)
assert im.width == 65536
assert im.height == 1
assert im.bands == 1
def test_identity(self):
im = pyvips.Image.identity()
assert im.width == 256
assert im.height == 1
assert im.bands == 1
assert im.format == pyvips.BandFormat.UCHAR
p = im(0, 0)
assert p[0] == 0.0
p = im(255, 0)
assert p[0] == 255.0
p = im(128, 0)
assert p[0] == 128.0
im = pyvips.Image.identity(ushort=True)
assert im.width == 65536
assert im.height == 1
assert im.bands == 1
def test_hist_cum(self):
im = pyvips.Image.identity()
sum = im.avg() * 256
cum = im.hist_cum()
p = cum(255, 0)
assert p[0] == sum
def test_hist_plot(self):
im = pyvips.Image.identity()
im2 = im.hist_plot()
assert im2.width == 256
assert im2.height == 256
assert im2.format == pyvips.BandFormat.UCHAR
assert im2.bands == 1
def test_hist_plot(self):
im = pyvips.Image.identity()
im2 = im.hist_plot()
self.assertEqual(im2.width, 256)
self.assertEqual(im2.height, 256)
self.assertEqual(im2.format, pyvips.BandFormat.UCHAR)
self.assertEqual(im2.bands, 1)
def test_identity(self):
im = pyvips.Image.identity()
assert im.width == 256
assert im.height == 1
assert im.bands == 1
assert im.format == pyvips.BandFormat.UCHAR
p = im(0, 0)
assert p[0] == 0.0
p = im(255, 0)
assert p[0] == 255.0
p = im(128, 0)
assert p[0] == 128.0
im = pyvips.Image.identity(ushort=True)
assert im.width == 65536
assert im.height == 1
assert im.bands == 1
assert im.format == pyvips.BandFormat.USHORT
p = im(0, 0)
assert p[0] == 0
p = im(99, 0)
assert p[0] == 99
p = im(65535, 0)
assert p[0] == 65535
def test_hist_map(self):
im = pyvips.Image.identity()
im2 = im.maplut(im)
self.assertEqual((im - im2).abs().max(), 0.0)
def avgze(image):
# since we use histograms
if image.format != "uchar" and image.format != "ushort":
raise Exception("uchar and ushort images only")
# take the histogram, and set the count for 0 pixels to 0, removing them
histze = image.hist_find().insert(pyvips.Image.black(1, 1), 0, 0)
# number of non-zero pixels in each band
nnz = [histze[i].avg() * histze.width * histze.height
for i in range(histze.bands)]
# multiply by the identity function and we get the sum of non-zero
# pixels ... for 16-bit images, we need a larger identity
# function
totalze = histze * pyvips.Image.identity(ushort=histze.width > 256)
# find average value in each band
avgze = [totalze[i].avg() * histze.width * histze.height / nnz[i]
for i in range(totalze.bands)]
return avgze