Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/machinevisiontoolbox/ImageWholeFeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1775,9 +1775,9 @@ def _compute_plot_series(
ylabel2 = "probability density"
elif type in ("cf", "cumulative"):
y = self.cf
maxy = y[
-1, 0
] # last row values are all the same, total number of pixels in plane
# the last row is the total number of pixels in each plane, y is 1D for a
# greyscale image and 2D, one column per plane, for a color image
maxy = np.max(y[-1])
ylabel1 = "cumulative frequency"
ylabel2 = "cumulative frequency"
elif type in ("cdf", "normalized"):
Expand Down
26 changes: 26 additions & 0 deletions tests/test_image_whole_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,5 +737,31 @@
)


class TestCumulativeFrequencyPlot(unittest.TestCase):
def tearDown(self):
plt.close("all")

def _plot(self, image, **kwargs):
with patch("matplotlib.pyplot.show"):
image.hist().plot(**kwargs)
return plt.gcf().axes

def test_greyscale(self):
im = Image.Read("eiffel-1.png", mono=True)
for type in ("cf", "cumulative"):

Check warning on line 751 in tests/test_image_whole_features.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/test_image_whole_features.py#L751

Redefining built-in 'type'
plt.close("all")
(ax,) = self._plot(im, type=type)
# the axis runs up to the number of pixels, which is where it ends
self.assertEqual(ax.get_ylim()[1], im.npixels)

def test_color_stack_and_overlay(self):
im = Image.Read("flowers1.png")
for style in ("stack", "overlay"):
plt.close("all")
axes = self._plot(im, type="cf", style=style)
for ax in axes:
self.assertEqual(ax.get_ylim()[1], im.npixels)


if __name__ == "__main__":
unittest.main()
Loading