diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..4c3586e --- /dev/null +++ b/.coveragerc @@ -0,0 +1,4 @@ +[run] +omit = + config.py + config-3.py diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 0f9f940..f483803 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -23,6 +23,6 @@ See [this page](https://plantcv.readthedocs.io/en/latest/pr_review_process/) for - [ ] Test coverage remains 100% - [ ] Documentation tested - [ ] New documentation pages added to `plantcv/mkdocs.yml` -- [ ] Changes to function input/output signatures added to `updating.md` +- [ ] Changes to function input/output signatures added to `changelog.md` - [ ] Code reviewed - [ ] PR approved diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 7a7852e..ca30610 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -16,7 +16,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: ['3.8', '3.9', '3.10'] + python-version: ['3.9', '3.10', '3.11'] os: [ubuntu-latest] env: OS: ${{ matrix.os }} @@ -30,8 +30,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - sudo apt-get update - sudo apt-get install --no-install-recommends libyaml-dev libegl1-mesa libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-shape0 libxcb-cursor0 xserver-xephyr xvfb + sudo apt-get install --no-install-recommends libyaml-dev libegl1-mesa libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-shape0 libxcb-cursor0 xserver-xephyr python -m pip install --upgrade pip pip install flake8 pytest pytest-cov pytest-qt pytest-xvfb ipython anyio - name: Lint with flake8 @@ -48,8 +47,9 @@ jobs: pip uninstall -y opencv-python pip install opencv-python-headless - name: Tests - uses: aganders3/headless-gui@v2 + uses: aganders3/headless-gui@v2.2 with: + xvfb-screen-size: 1280x720x24 run: pytest --cov-report=xml --cov=./ - name: Upload coverage to Deepsource uses: deepsourcelabs/test-coverage-action@master diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a612ad9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/docs/changelog.md b/docs/changelog.md index 820a7f1..4d0ef44 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,3 +1,35 @@ ## Changelog All notable changes to this project will be documented below. + +#### annotate.get_centroids + +* v0.1dev: coords_list = **annotate.get_centroids**(*bin_img*) + +#### annotate.napari_classes + +* v0.1dev: class_list = **annotate.napari_classes**(*viewer*) + +#### annotate.napari_join_labels + +* v0.1dev: relabeled_mask, mask_dict = **annotate.napari_join_labels**(*img, viewer*) + +#### annotate.napari_label_classes + +* v0.1dev: viewer = **annotate.napari_label_classes**(*img, classes, size=10, shape='square', importdata=False, show=True*) + +#### annotate.napari_open + +* v0.1dev: viewer = **annotate.napari_open**(*img, mode = 'native', show=True*) + +#### annotate.napari_read_coor + +* v0.1dev: data = **annotate.napari_read_coor**(*coor, dataformat='yx'*) + +#### annotate.napari_save_coor + +* v0.1dev: datadict = **annotate.napari_save_coor**(*viewer, filepath*) + +#### annotate.Points + +* v0.1dev: viewer = **annotate.Points**(*img, figsize=(12,6), label="dafault"*) diff --git a/docs/get_centroids.md b/docs/get_centroids.md new file mode 100644 index 0000000..87dbb08 --- /dev/null +++ b/docs/get_centroids.md @@ -0,0 +1,44 @@ +## Get Centroids + +Extract the centroid coordinate (column,row) from regions in a binary image. + +**plantcv.annotate.get_centroids**(*bin_img*) + +**returns** list containing coordinates of centroids + +- **Parameters:** + - bin_img - Binary image containing the connected regions to consider +- **Context:** + - Given an arbitrary mask of the objects of interest, `get_centroids` + returns a list of coordinates that can the be imported into the annotation class [Points](Points.md). + +- **Example use:** + - Below + +**Binary image** + +![count_img](img/documentation_images/get_centroids/discs_mask.png) + +```python + +from plantcv import plantcv as pcv + +# Set global debug behavior to None (default), "print" (to file), +# or "plot" +pcv.params.debug = "plot" + +# Apply get centroids to the binary image +coords = pcv.annotate.get_centroids(bin_img=binary_img) +print(coords) +# [[1902, 600], [1839, 1363], [1837, 383], [1669, 1977], [1631, 1889], [1590, 1372], [1550, 1525], +# [1538, 1633], [1522, 1131], [1494, 2396], [1482, 1917], [1446, 1808], [1425, 726], [1418, 2392], +# [1389, 198], [1358, 1712], [1288, 522], [1289, 406], [1279, 368], [1262, 1376], [1244, 1795], +# [1224, 1327], [1201, 624], [1181, 725], [1062, 85], [999, 840], [885, 399], [740, 324], [728, 224], +# [697, 860], [660, 650], [638, 2390], [622, 1565], [577, 497], [572, 2179], [550, 2230], [547, 1826], +# [537, 892], [538, 481], [524, 2144], [521, 2336], [497, 201], [385, 1141], [342, 683], [342, 102], +# [332, 1700], [295, 646], [271, 60], [269, 1626], [210, 1694], [189, 878], [178, 1570], [171, 2307], +# [61, 286], [28, 2342]] + +``` + +**Source Code:** [Here](https://github.com/danforthcenter/plantcv-annotate/blob/main/plantcv/annotate/get_centroids.py) diff --git a/docs/img/documentation_images/get_centroids/discs_mask.png b/docs/img/documentation_images/get_centroids/discs_mask.png new file mode 100644 index 0000000..357fc23 Binary files /dev/null and b/docs/img/documentation_images/get_centroids/discs_mask.png differ diff --git a/docs/napari_join_labels.md b/docs/napari_join_labels.md index 1a118ca..b8cd44e 100644 --- a/docs/napari_join_labels.md +++ b/docs/napari_join_labels.md @@ -31,10 +31,10 @@ img, path, name = pcv.readimage("./grayimg.png") viewer = pcvan.napari_label_classes(img=img, ['background', 'wing','seed']) -labeledmask, mask_dict = pcvan.napari_join_lables(img=img, viewer) - # Should open interactive napari viewer +labeledmask, mask_dict = pcvan.napari_join_lables(img=img, viewer=viewer) + ``` ![Screenshot](img/documentation_images/napari_label_classes/napari_label_classes.png) diff --git a/docs/napari_label_classes.md b/docs/napari_label_classes.md index dec120c..3b75029 100644 --- a/docs/napari_label_classes.md +++ b/docs/napari_label_classes.md @@ -1,24 +1,27 @@ ## Label Image with Napari -This function opens an image in Napari and then defines a set of classes to label. A random shape label is assigned to each class. -Image can be annotate as long as viewer is open. +This function opens an image in Napari and then defines a set of Points layers with the user-defined labels called `classes`. A random `shape` of the annotation symbol is assigned to each of the `classes`. +Image can be annotated as long as viewer is open. -**plantcv.annotate.napari_label_classes*(*img, classes, size=10, importdata=False, show=True*) + +**plantcv.annotate.napari_label_classes*(*img, classes, size=10, shape='square', importdata=False, show=True*) **returns** napari viewer object - **Parameters:** - img - image data (compatible with gray, RGB, and hyperspectral data. If data is hyperspecral it should be the array e.g. hyperspectral.array_data) - classes - list of classes to label. This option is not necessary if data is data is imported. - - size - integer pixel size of label, best if even number + - size - integer pixel size of label (also adjustable from the interactive Napari viewer) + - shape - shape of the annotation symbol. Can be 'o', 'arrow', 'clobber', 'cross', 'diamond', 'disc', 'hbar', 'ring', 'square' (default), 'star', 'tailed_arrow', + 'triangle_down', 'triangle_up', 'vbar', or 'x' (also adjustable from the interactive Napari viewer) - importdata - dictionary of data, data saved from napari_save_coor or data imported from napari_read_coor - - show - if show = True, viewer is launched. False setting is useful for test purposes. + - show - if `show=True`, viewer is launched. `False` setting is useful for test purposes. - **Context:** - - Adding class labels to images. Works best on an image that has objects segmented/classified with contours/clusters labeled with values (e.g. labeled mask, output of kmeans clustering). + - Adding one or more classes of points layer for annotation of the image. - **Example use:** - - Labeling output of kmeans clustering into classes. Labeling points. + - Ground truth counting, labeling classes of objects of interest. ```python @@ -29,9 +32,8 @@ import napari # Create an instance of the Points class img, path, name = pcv.readimage("./grayimg.png") -viewer = pcvan.napari_label_classes(img=img, classes=['background', 'wing','seed'], size = 30) - -# Should open interactive napari viewer +# Opens interactive napari viewer +viewer = pcvan.napari_label_classes(img=img, classes=['background', 'wing','seed'], size=30) ``` diff --git a/docs/napari_open.md b/docs/napari_open.md index c699a85..395cc98 100644 --- a/docs/napari_open.md +++ b/docs/napari_open.md @@ -1,13 +1,14 @@ ## Open Image with Napari -Open image data (e.g. RGB, gray, hyperspectral) with an interactive Napari viewer. If a gray image is opened, the image will be pseudocolored for better visualization. +Open image data (e.g. RGB, gray, hyperspectral) with an interactive Napari viewer. Labeled masks may be colorized for better visualization. -**plantcv.annotate.napari_open**(*img, show=True*) +**plantcv.annotate.napari_open**(*img, mode='native', show=True*) **returns** napari viewer object - **Parameters:** - - img - image data (compatible with gray, RGB, and hyperspectral data. If data is hyperspecral it should be the array e.g. hyperspectral.array_data) + - img - image data (compatible with gray, RGB, and hyperspectral data. If data is hyperspecral it should be the array e.g. `hyperspectral.array_data`) + - mode - 'native' or 'colorize'. If 'colorized' is selected gray images will be colorized. - show - if show = True, viewer is launched. False setting is useful for test purposes. - **Context:** @@ -24,7 +25,7 @@ import plantcv.annotate as pcvan # Create an instance of the Points class img, path, name = pcv.readimage("./grayimg.png") -viewer = pcvan.napari_open(img=img) +viewer = pcvan.napari_open(img=img, mode='colorize') # Should open interactive napari viewer diff --git a/docs/napari_read_coor.md b/docs/napari_read_coor.md index 668cc91..2d22fc9 100644 --- a/docs/napari_read_coor.md +++ b/docs/napari_read_coor.md @@ -7,14 +7,14 @@ Save Points Labeled in Napari to a File **returns** dictionary of points labeled by class - **Parameters:** - - coor - dictionary object of coordinates or a path to json datafile with dictionary of point coordinates + - coor - dictionary object of coordinates, or a path to json datafile with dictionary of point coordinates - dataformat - either 'yx' or 'xy', Napari takes data as y,x format. If data is 'xy' data is converted from x,y to y,x - **Context:** - - Import data from a file and convert to Napari format data if necessary + - Import previously labeled points, or points from other functions (e.g. [`pcvan.napari_read_coor`](napari_read_coor.md)) - **Example use:** - - Import previously labeled points, or points from other functions (e.g. detect_centroid) + - Below ```python diff --git a/docs/napari_save_coor.md b/docs/napari_save_coor.md index f23815b..6ea22e1 100644 --- a/docs/napari_save_coor.md +++ b/docs/napari_save_coor.md @@ -11,7 +11,7 @@ Save Points Labeled in Napari to a File - Filepath - File to save data. If the file exits an extension will be added. - **Context:** - - Save points labeled in Napari to a file in case the same points need to be used. + - Save points labeled in Napari to a file to checkpoint annotation progress or reuse. - **Example use:** - Save points labeled to a file @@ -23,13 +23,11 @@ import plantcv.annotate as pcvan # Create an instance of the Points class img, path, name = pcv.readimage("./grayimg.png") - +# Should open interactive napari viewer viewer = pcvan.napari_label_classes(img=img, classes=['background', 'wing','seed']) dictobj = pcvan.napari_save_coor(viewer, 'testdata.txt') -# Should open interactive napari viewer - ``` ![Screenshot](img/documentation_images/napari_label_classes/napari_label_classes.png) diff --git a/mkdocs.yml b/mkdocs.yml index 8dc95de..2be77e3 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -25,7 +25,7 @@ nav: - Napari Read Coor: napari_read_coor.md - Napari Save Coor: napari_save_coor.md - Points: Points.md - + - Get Centroids: get_centroids.md markdown_extensions: - toc: permalink: True diff --git a/plantcv/annotate/__init__.py b/plantcv/annotate/__init__.py index 83ad404..204af28 100644 --- a/plantcv/annotate/__init__.py +++ b/plantcv/annotate/__init__.py @@ -1,3 +1,6 @@ +from importlib.metadata import version +from plantcv.annotate.classes import Points +from plantcv.annotate.get_centroids import get_centroids from plantcv.annotate.napari_classes import napari_classes from plantcv.annotate.napari_open import napari_open from plantcv.annotate.napari_label_classes import napari_label_classes @@ -6,8 +9,12 @@ from plantcv.annotate.napari_read_coor import napari_read_coor from plantcv.annotate.napari_points_mask import napari_points_mask +# Auto versioning +__version__ = version("plantcv-annotate") __all__ = [ + "Points", + "get_centroids", "napari_classes", "napari_open", "napari_label_classes", diff --git a/plantcv/annotate/classes.py b/plantcv/annotate/classes.py new file mode 100644 index 0000000..455701e --- /dev/null +++ b/plantcv/annotate/classes.py @@ -0,0 +1,160 @@ +# Class helpers + +# Imports +import cv2 +import json +from math import floor +import matplotlib.pyplot as plt +from plantcv.plantcv.annotate.points import _find_closest_pt +from plantcv.plantcv import warn + + +class Points: + """Point annotation/collection class to use in Jupyter notebooks. It allows the user to + interactively click to collect coordinates from an image. Left click collects the point and + right click removes the closest collected point. + """ + + def __init__(self, img, figsize=(12, 6), label="default", color="r", view_all=False): + """Points initialization method. + + Parameters + ---------- + img : numpy.ndarray + image to annotate + figsize : tuple, optional + figure plotting size, by default (12, 6) + label : str, optional + class label, by default "default" + """ + self.img = img + self.figsize = figsize + self.label = label # current label + self.color = color # current color + self.view_all = view_all # a flag indicating whether or not view all labels + self.coords = {} # dictionary of all coordinates per group label + self.events = [] # includes right and left click events + self.count = {} # a dictionary that saves the counts of different groups (labels) + self.sample_labels = [] # list of all sample labels, one to one with points collected + self.colors = {} # all used colors + + self.view(label=self.label, color=self.color, view_all=self.view_all) + + def onclick(self, event): + """Handle mouse click events + + Parameters + ---------- + event : matplotlib.backend_bases.MouseEvent + matplotlib MouseEvent object + """ + print(type(event)) + self.events.append(event) + if event.button == 1: + # Add point to the plot + self.ax.plot(event.xdata, event.ydata, marker='x', c=self.color) + self.coords[self.label].append((floor(event.xdata), floor(event.ydata))) + self.count[self.label] += 1 + self.sample_labels.append(self.label) + else: + idx_remove, _ = _find_closest_pt((event.xdata, event.ydata), self.coords[self.label]) + # remove the closest point to the user right clicked one + self.coords[self.label].pop(idx_remove) + self.count[self.label] -= 1 + idx_remove = idx_remove + self.p_not_current + self.ax.lines[idx_remove].remove() + self.sample_labels.pop(idx_remove) + self.fig.canvas.draw() + + def print_coords(self, filename): + """Save collected coordinates to a file. + + Parameters + ---------- + filename : str + output filename + """ + # Open the file for writing + with open(filename, "w") as fp: + # Save the data in JSON format with indentation + json.dump(obj=self.coords, fp=fp, indent=4) + + def import_list(self, coords, label="default"): + """Import coordinates. + + Parameters + ---------- + coords : list + list of coordinates (tuples) + label : str, optional + class label, by default "default" + """ + if label not in self.coords: + self.coords[label] = [] + for (y, x) in coords: + self.coords[label].append((x, y)) + self.count[label] = len(self.coords[label]) + self.view(label=label, color=self.color, view_all=False) + else: + warn(f"{label} already included and counted, nothing is imported!") + + def import_file(self, filename): + """Import coordinates from a file. + + Parameters + ---------- + filename : str + JSON file containing Points annotations + """ + with open(filename, "r") as fp: + coords = json.load(fp) + + keys = list(coords.keys()) + + for key in keys: + keycoor = coords[key] + keycoor = list(map(lambda sub: (sub[1], sub[0]), keycoor)) + self.import_list(keycoor, label=key) + + def view(self, label="default", color="r", view_all=False): + """View coordinates for a specific class label. + + Parameters + ---------- + label : str, optional + class label, by default "default" + color : str, optional + marker color, by default "r" + view_all : bool, optional + view all classes or a single class, by default False + """ + if label not in self.coords and color in self.colors.values(): + warn("The color assigned to the new class label is already used, if proceeding, " + "items from different classes will not be distinguishable in plots!") + self.label = label + self.color = color + self.view_all = view_all + + if self.label not in self.coords: + self.coords[self.label] = [] + self.count[self.label] = 0 + self.colors[self.label] = self.color + + self.fig, self.ax = plt.subplots(1, 1, figsize=self.figsize) + + self.events = [] + self.fig.canvas.mpl_connect('button_press_event', self.onclick) + + self.ax.imshow(cv2.cvtColor(self.img, cv2.COLOR_BGR2RGB)) + self.ax.set_title("Please left click on objects\n Right click to remove") + self.p_not_current = 0 + # if view_all is True, show all already marked markers + if self.view_all: + for k in self.coords: + for (x, y) in self.coords[k]: + self.ax.plot(x, y, marker='x', c=self.colors[k]) + if self.label not in self.coords or len(self.coords[self.label]) == 0: + self.p_not_current += 1 + else: + for (x, y) in self.coords[self.label]: + self.ax.plot(x, y, marker='x', c=self.color) diff --git a/plantcv/annotate/get_centroids.py b/plantcv/annotate/get_centroids.py new file mode 100644 index 0000000..8fbf46b --- /dev/null +++ b/plantcv/annotate/get_centroids.py @@ -0,0 +1,28 @@ +# Get centroids from mask objects + +from skimage.measure import label, regionprops + + +def get_centroids(bin_img): + """Get the coordinates (row,column) of the centroid of each connected region in a binary image. + + Inputs: + bin_img = Binary image containing the connected regions to consider + + Returns: + coords = List of coordinates (row,column) of the centroids of the regions + + :param bin_img: numpy.ndarray + :return coords: list + """ + # find contours in the binary image + labeled_img = label(bin_img) + # measure regions + obj_measures = regionprops(labeled_img) + coords = [] + for obj in obj_measures: + # Convert coord values to int + coord = tuple(map(int, obj.centroid)) + coords.append(coord) + + return coords diff --git a/plantcv/annotate/napari_join_labels.py b/plantcv/annotate/napari_join_labels.py index c01dc38..1848258 100755 --- a/plantcv/annotate/napari_join_labels.py +++ b/plantcv/annotate/napari_join_labels.py @@ -20,7 +20,7 @@ def napari_join_labels(img, viewer): labeled with values (e.g. labeled mask, output of kmeans clustering). viewer = Napari Viewer with classes labeled (e.g viewer from napari_label_classes) - show = if show is True the viewer is launched. This opetion is useful for + show = if show is True the viewer is launched. This option is useful for running tests without triggering the viewer. Returns: @@ -29,7 +29,7 @@ def napari_join_labels(img, viewer): :param img: numpy.ndarray :param viewer: Napari Viewer object - :return labeled_imd: numpy.ndarray + :return labeled_img: numpy.ndarray :return mask_dict: dict of numpy.ndarray """ diff --git a/plantcv/annotate/napari_label_classes.py b/plantcv/annotate/napari_label_classes.py index 5cf2536..8809974 100755 --- a/plantcv/annotate/napari_label_classes.py +++ b/plantcv/annotate/napari_label_classes.py @@ -25,6 +25,7 @@ def napari_label_classes(img, classes=False, size=10, importdata = dictionary of values in Napari format (y,x). Output of napari_read_coor show = if show is True the viewer is launched. This opetion is useful for + running tests without triggering the viewer. Returns: @@ -36,6 +37,7 @@ def napari_label_classes(img, classes=False, size=10, :param shape: str :param importdata: dict :param show: str + :return viewer: napari viewer object """ diff --git a/plantcv/annotate/napari_open.py b/plantcv/annotate/napari_open.py index 341fa36..9aff3e8 100755 --- a/plantcv/annotate/napari_open.py +++ b/plantcv/annotate/napari_open.py @@ -6,25 +6,26 @@ from skimage.color import label2rgb -def napari_open(img, show=True): - """ - open img in napari and label classes +def napari_open(img, mode='native', show=True): + """Open an image with a napari interactive viewer - Inputs: - img = img (grayimg, rgbimg, or hyperspectral image array data e.g. - hyperspectraldata.array_data) - show = if show is True the viewer is launched. This opetion is useful for + Parameters + ---------- + img : numpy.ndarray + Image to be opened, img can be gray, rgb, or multispectral + mode: str + Viewing mode, either 'native' (default) or 'colorize' + show: bool + if show is True the viewer is launched. This option is useful for running tests without triggering the viewer. - Returns: - viewer = napari viewer object - - :param img: numpy.ndarray - :return viewer: napari viewer object - + Returns + ------- + napari.viewer.Viewer + Napari viewer object """ shape = np.shape(img) - if len(shape) == 2: + if len(shape) == 2 and mode == 'colorize': colorful = label2rgb(img) img = (255*colorful).astype(np.uint8) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) diff --git a/plantcv/annotate/napari_save_coor.py b/plantcv/annotate/napari_save_coor.py index 2041141..5011000 100755 --- a/plantcv/annotate/napari_save_coor.py +++ b/plantcv/annotate/napari_save_coor.py @@ -36,6 +36,5 @@ def napari_save_coor(viewer, filepath): filepath = str(filepath)+"_1.txt" with open(filepath, 'w') as fp: json.dump(datadict, fp) - fp.close() return datadict diff --git a/pyproject.toml b/pyproject.toml index 8a6251d..5abfaf1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools >= 61.0"] +requires = ["setuptools >= 64.0", "setuptools_scm>=8"] build-backend = "setuptools.build_meta" [tool.setuptools.packages.find] @@ -27,12 +27,17 @@ classifiers = [ "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", "Intended Audience :: Science/Research", ] + [project.optional-dependencies] test = [ "pytest", + "pytest-cov", "pytest-qt" ] + [project.urls] Homepage = "https://plantcv.org" Documentation = "https://plantcv.readthedocs.io" -Repository = "https://github.com/danforthcenter/plantcv-annotate" \ No newline at end of file +Repository = "https://github.com/danforthcenter/plantcv-annotate" + +[tool.setuptools_scm] diff --git a/tests/conftest.py b/tests/conftest.py index 75e0997..180c56a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,6 @@ +import os import pytest import matplotlib -import os # Disable plotting @@ -11,14 +11,17 @@ class TestData: def __init__(self): """Initialize simple variables.""" # Test data directory - self.datadir = os.path.join(os.path.dirname(os.path.abspath(__file__)), - "testdata") + self.datadir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "testdata") + # Flat image directory + self.snapshot_dir = os.path.join(self.datadir, "snapshot_dir") # RGB image - filename_rgb = "setaria_small_plant_rgb.png" - self.small_rgb_img = os.path.join(self.datadir, filename_rgb) + self.small_rgb_img = os.path.join(self.datadir, "setaria_small_plant_rgb.png") + # Binary image + self.small_bin_img = os.path.join(self.datadir, "setaria_small_plant_mask.png") + # Text file with tuple coordinates (by group label) + self.pollen_coords = os.path.join(self.datadir, "points_file_import.coords") # Kmeans Clustered Gray image - filename_kmeans = "silphium_seed_labeled_example.png" - self.kmeans_seed_gray_img = os.path.join(self.datadir, filename_kmeans) + self.kmeans_seed_gray_img = os.path.join(self.datadir, "silphium_seed_labeled_example.png") # Small Hyperspectral image filename_hyper = "corn-kernel-hyperspectral.raw" self.envi_sample_data = os.path.join(self.datadir, filename_hyper) @@ -27,6 +30,7 @@ def __init__(self): self.coor_data = os.path.join(self.datadir, filename_coor) + @pytest.fixture(scope="session") def test_data(): """Test data object for the main PlantCV package.""" diff --git a/tests/test_annotate_get_centroids.py b/tests/test_annotate_get_centroids.py new file mode 100644 index 0000000..54c4db3 --- /dev/null +++ b/tests/test_annotate_get_centroids.py @@ -0,0 +1,12 @@ +import cv2 +from plantcv.annotate.get_centroids import get_centroids + + +def test_get_centroids(test_data): + """Test for PlantCV.""" + # Read in test data + mask = cv2.imread(test_data.small_bin_img, -1) + + coor = get_centroids(bin_img=mask) + + assert coor == [(166, 214)] diff --git a/tests/test_annotate_points.py b/tests/test_annotate_points.py new file mode 100644 index 0000000..d7828b3 --- /dev/null +++ b/tests/test_annotate_points.py @@ -0,0 +1,159 @@ +"""Tests for annotate.Points.""" +import os +import cv2 +import matplotlib +from plantcv.annotate.classes import Points + + +def test_points(test_data): + """Test for plantcv-annotate.""" + # Read in a test grayscale image + img = cv2.imread(test_data.small_rgb_img) + + # initialize interactive tool + drawer_rgb = Points(img, figsize=(5, 5)) + + # simulate mouse clicks + # event 1, left click to add point + e1 = matplotlib.backend_bases.MouseEvent(name="button_press_event", canvas=drawer_rgb.fig.canvas, + x=0, y=0, button=1) + point1 = (200, 200) + e1.xdata, e1.ydata = point1 + drawer_rgb.onclick(e1) + + # event 2, left click to add point + e2 = matplotlib.backend_bases.MouseEvent(name="button_press_event", canvas=drawer_rgb.fig.canvas, + x=0, y=0, button=1) + e2.xdata, e2.ydata = (300, 200) + drawer_rgb.onclick(e2) + + # event 3, left click to add point + e3 = matplotlib.backend_bases.MouseEvent(name="button_press_event", canvas=drawer_rgb.fig.canvas, + x=0, y=0, button=1) + e3.xdata, e3.ydata = (50, 50) + drawer_rgb.onclick(e3) + + # event 4, right click to remove point with exact coordinates + e4 = matplotlib.backend_bases.MouseEvent(name="button_press_event", canvas=drawer_rgb.fig.canvas, + x=0, y=0, button=3) + e4.xdata, e4.ydata = (50, 50) + drawer_rgb.onclick(e4) + + # event 5, right click to remove point with coordinates close but not equal + e5 = matplotlib.backend_bases.MouseEvent(name="button_press_event", canvas=drawer_rgb.fig.canvas, + x=0, y=0, button=3) + e5.xdata, e5.ydata = (301, 200) + drawer_rgb.onclick(e5) + + assert drawer_rgb.coords["default"][0] == point1 + + +def test_points_print_coords(test_data, tmpdir): + """Test for plantcv-annotate.""" + cache_dir = tmpdir.mkdir("cache") + filename = os.path.join(cache_dir, 'plantcv_print_coords.txt') + # Read in a test image + img = cv2.imread(test_data.small_rgb_img) + + # initialize interactive tool + drawer_rgb = Points(img, figsize=(5, 5)) + + # simulate mouse clicks + # event 1, left click to add point + e1 = matplotlib.backend_bases.MouseEvent(name="button_press_event", canvas=drawer_rgb.fig.canvas, + x=0, y=0, button=1) + point1 = (200, 200) + e1.xdata, e1.ydata = point1 + drawer_rgb.onclick(e1) + + # event 2, left click to add point + e2 = matplotlib.backend_bases.MouseEvent(name="button_press_event", canvas=drawer_rgb.fig.canvas, + x=0, y=0, button=1) + e2.xdata, e2.ydata = (300, 200) + drawer_rgb.onclick(e2) + + # Save collected coords out + drawer_rgb.print_coords(filename) + assert os.path.exists(filename) + + +def test_points_import_list(test_data): + """Test for plantcv-annotate.""" + # Read in a test image + img = cv2.imread(test_data.small_rgb_img) + # initialize interactive tool + drawer_rgb = Points(img, figsize=(5, 5), label="default") + totalpoints1 = [(158, 531), (361, 112), (500, 418), (269.25303806488864, 385.69839981447126), + (231.21964288863632, 445.995245825603), (293.37177646934134, 448.778177179963), + (240.49608073650273, 277.1640769944342), (279.4571196975417, 240.05832560296852), + (77.23077461405376, 165.84682282003712), (420, 364), (509.5127783246289, 353.2308673469388), + (527.1380102355752, 275.3087894248609), (445.50535717435065, 138.94515306122452)] + drawer_rgb.import_list(coords=totalpoints1, label="imported") + + assert len(drawer_rgb.coords["imported"]) == 13 + + +def test_points_import_list_warn(test_data): + """Test for plantcv-annotate.""" + # Read in a test image + img = cv2.imread(test_data.small_rgb_img) + # initialize interactive tool + drawer_rgb = Points(img, figsize=(5, 5), label="default") + totalpoints1 = [(158, 531), (361, 112), (500, 418), (445.50535717435065, 138.94515306122452)] + drawer_rgb.import_list(coords=totalpoints1) + + assert len(drawer_rgb.coords["default"]) == 0 + + +def test_points_import_file(test_data): + """Test for plantcv-annotate.""" + img = cv2.imread(test_data.small_rgb_img) + counter = Points(img, figsize=(5, 5)) + file = test_data.pollen_coords + counter.import_file(file) + + assert counter.count['total'] == 70 + + +def test_points_view(test_data): + """Test for plantcv-annotate.""" + # Read in a test grayscale image + img = cv2.imread(test_data.small_rgb_img) + + # initialize interactive tool + drawer_rgb = Points(img, figsize=(5, 5)) + + # simulate mouse clicks + # event 1, left click to add point + e1 = matplotlib.backend_bases.MouseEvent(name="button_press_event", canvas=drawer_rgb.fig.canvas, + x=0, y=0, button=1) + point1 = (200, 200) + e1.xdata, e1.ydata = point1 + drawer_rgb.onclick(e1) + drawer_rgb.view(label="new", view_all=True) + e2 = matplotlib.backend_bases.MouseEvent(name="button_press_event", canvas=drawer_rgb.fig.canvas, + x=0, y=0, button=1) + e2.xdata, e2.ydata = (300, 200) + drawer_rgb.onclick(e2) + drawer_rgb.view(view_all=False) + + assert str(drawer_rgb.fig) == "Figure(500x500)" + + +def test_points_view_warn(test_data): + """Test for plantcv-annotate.""" + # Read in a test grayscale image + img = cv2.imread(test_data.small_rgb_img) + + # initialize interactive tool, implied default label and "r" color + drawer_rgb = Points(img, figsize=(5, 5)) + + # simulate mouse clicks, event 1=left click to add point + e1 = matplotlib.backend_bases.MouseEvent(name="button_press_event", canvas=drawer_rgb.fig.canvas, + x=0, y=0, button=1) + point1 = (200, 200) + e1.xdata, e1.ydata = point1 + drawer_rgb.onclick(e1) + drawer_rgb.view(label="new", color='r') + + assert str(drawer_rgb.fig) == "Figure(500x500)" diff --git a/tests/test_napari_label_classes.py b/tests/test_napari_label_classes.py index 6ccdce3..d6eac8c 100644 --- a/tests/test_napari_label_classes.py +++ b/tests/test_napari_label_classes.py @@ -15,4 +15,5 @@ def test_napari_label_classes_gray(test_data): face_color="red", size=5) assert len(viewer.layers['total'].data) == 1 + viewer.close() diff --git a/tests/test_napari_open.py b/tests/test_napari_open.py index 5b1ef78..33c72a4 100644 --- a/tests/test_napari_open.py +++ b/tests/test_napari_open.py @@ -29,6 +29,19 @@ def test_napari_open_gray(test_data): viewer.close() +def test_napari_open_gray1(test_data): + """Test for PlantCV.Annotate""" + # Read in test data + img, _, _ = readimage(test_data.kmeans_seed_gray_img) + viewer = napari_open(img, mode='colorize', show=False) + coor = [(25, 25), (50, 50)] + viewer.add_points(np.array(coor), symbol="o", name="total", + face_color="red", size=1) + + assert len(viewer.layers['total'].data) == 2 + viewer.close() + + def test_napari_open_envi(test_data): """Test for PlantCV.Annotate""" # Read in test data diff --git a/tests/testdata/points_file_import.coords b/tests/testdata/points_file_import.coords new file mode 100644 index 0000000..2be1117 --- /dev/null +++ b/tests/testdata/points_file_import.coords @@ -0,0 +1,306 @@ +{ + "total": [ + [ + 1524, + 59 + ], + [ + 1642, + 78 + ], + [ + 723, + 159 + ], + [ + 1711, + 218 + ], + [ + 736, + 263 + ], + [ + 1431, + 275 + ], + [ + 1573, + 338 + ], + [ + 531, + 358 + ], + [ + 1437, + 365 + ], + [ + 904, + 380 + ], + [ + 1255, + 387 + ], + [ + 1140, + 417 + ], + [ + 112, + 561 + ], + [ + 2056, + 690 + ], + [ + 418, + 700 + ], + [ + 1738, + 703 + ], + [ + 1255, + 959 + ], + [ + 1791, + 1042 + ], + [ + 1310, + 1065 + ], + [ + 902, + 1084 + ], + [ + 1319, + 1131 + ], + [ + 1084, + 1156 + ], + [ + 457, + 1183 + ], + [ + 1763, + 1190 + ], + [ + 1407, + 1232 + ], + [ + 2053, + 1283 + ], + [ + 1140, + 1383 + ], + [ + 566, + 1393 + ], + [ + 240, + 1403 + ], + [ + 1681, + 1421 + ], + [ + 398, + 470 + ], + [ + 438, + 432 + ], + [ + 446, + 502 + ], + [ + 919, + 252 + ], + [ + 947, + 204 + ], + [ + 997, + 219 + ], + [ + 967, + 267 + ], + [ + 1034, + 400 + ], + [ + 1074, + 364 + ], + [ + 1104, + 329 + ], + [ + 1165, + 267 + ], + [ + 1235, + 304 + ], + [ + 1272, + 262 + ], + [ + 1297, + 299 + ], + [ + 1350, + 249 + ], + [ + 1387, + 229 + ], + [ + 1488, + 492 + ], + [ + 1565, + 202 + ], + [ + 1595, + 247 + ], + [ + 1633, + 274 + ], + [ + 839, + 101 + ], + [ + 861, + 162 + ], + [ + 914, + 46 + ], + [ + 1052, + 56 + ], + [ + 1102, + 149 + ], + [ + 1150, + 127 + ], + [ + 280, + 442 + ], + [ + 240, + 477 + ], + [ + 93, + 490 + ], + [ + 270, + 733 + ], + [ + 351, + 713 + ], + [ + 363, + 627 + ], + [ + 215, + 1036 + ], + [ + 498, + 973 + ], + [ + 606, + 1224 + ], + [ + 646, + 1264 + ], + [ + 353, + 1244 + ], + [ + 343, + 1284 + ], + [ + 300, + 1244 + ], + [ + 323, + 1196 + ] + ], + "germinated": [ + [ + 1485, + 494 + ], + [ + 95, + 481 + ], + [ + 1588, + 974 + ], + [ + 1994, + 1039 + ], + [ + 1901, + 198 + ] + ] +} \ No newline at end of file diff --git a/tests/testdata/setaria_small_plant_mask.png b/tests/testdata/setaria_small_plant_mask.png new file mode 100644 index 0000000..2c990da Binary files /dev/null and b/tests/testdata/setaria_small_plant_mask.png differ