[general]
name=Plant Pixel Extractor
qgisMinimumVersion=3.28
qgisMaximumVersion=4.99
description=Plant and soil segmentation for RGB, multispectral and hyperspectral drone imagery.
version=4.11.1
author=Anish Bhattarai
email=leoanish9@gmail.com
about=Plant Pixel Extractor (PPE) separates plant pixels from soil in drone orthomosaics without training data. It ranks the vegetation indices the image allows by how well they spread plant from soil, splits the three best with four automatic thresholds (Otsu, CDF knee, k-means, multi-Otsu) and lets the twelve results vote. Guards remove shadows, algae on wet soil and grey objects. Works with RGB cameras, multispectral sensors (MicaSense, Sequoia, DJI and others, as one file, a folder or separate band files) and hyperspectral cubes; thermal bands are ignored. The image appears on the map as soon as it is chosen, a live slider previews the mask, and results export as rasters, per-band and per-index layers, and plot statistics for an AOI. A Batch tab runs a whole folder of images and lets you review each mask. Two more goals use the same mask: a plant counter (early season) that proposes one point per plant, finds the crop rows itself and marks plants between rows as possible weeds, which you then check and correct on the map with add, remove and plant or weed tools; after a run, weeds between and inside the crop rows are listed in What PPE found, you review them on the map with one click per plant, and leave them out for a clean crop-only mask; training data for a fast plant and soil model, image tiles with PPE labels and no hand labelling (the included tools/ppe_train.py trains, checks and updates the model outside QGIS and needs PyTorch); and create labels for your own machine-learning model: plant, soil and (optionally) weed points from clear pixels only, weeds never labelled as plant, spread over the whole range of the image by conditioned Latin hypercube sampling, optionally inside an area you draw, which you check on the map and grow into buffers that never cross into the other class. No extra installation: it uses the GDAL and NumPy that ship with QGIS. Works on QGIS 3.28 to 4.x; tested on QGIS 3.34 (Linux); feedback from Windows and macOS users is welcome.
category=Raster
icon=icons/ppe.svg
experimental=False
deprecated=False
hasProcessingProvider=False
tags=drone,raster,plant,canopy,multispectral,vegetation,segmentation,plant count,batch,deep learning
repository=https://github.com/Leoanish/ppe-qgis
tracker=https://github.com/Leoanish/ppe-qgis/issues
homepage=https://github.com/Leoanish/ppe-qgis
changelog=4.11.1 (all changes since 4.5.2):
    - New goal Create labels: plant and soil (and optional weed) points on clear pixels only, spread over the image by conditioned Latin hypercube sampling; optional area; check them on the map; grow them with a live buffer slider that follows the leaf or soil; export points, buffers, label raster and pixel table.
    - Plant counter for crop rows: finds the rows and the plant spacing (from confident single plants), splits touching plants by length divided by spacing, marks weeds between and inside the rows; Split, Merge, Plant or weed, Add and Remove tools; counting inside a drawn area; clear summary of what is counted.
    - Weeds in What PPE found: after every run, weeds between and inside the rows are listed; review them on the map with one click per plant (weed or crop) and leave them out for a clean plant-only mask. Every kind on the card now has Leave out and Add.
    - Crop-only mask from the reviewed count. On PhenoBench, after checking, weeds fell from 14.0 to 6.5 percent of the mask (crop IoU 68.3 to 73.6).
    - Weeds are never labelled as plant in Create labels or Training data; labels can use your finalized, weed-reviewed mask.
    - Faster and lighter, same results: a run uses at most about 1 GB of memory, the image sample is read on all CPU cores, the crop-row search is multi-threaded. A full run on a 34 megapixel 5-band field takes 13 s instead of 18 s; the plant counter is about 40 percent faster.
    - Each image gets its own output folder; switching goals tidies the map; PPE always opens on the Plant mask goal.
    - Ready for QGIS 4 (Qt6) and still works on QGIS 3.28 and later.
    - Passes the plugins.qgis.org validator and security scan (Bandit, detect-secrets and Flake8: no findings).
    4.5.2: Plugin page description updated (batch, plant counter, training data). No change in how PPE works.
    4.5.1: Crop rows are found automatically: PPE finds the direction and spacing of the rows itself (15 to 150 cm, any crop) from the plant pixels, fitted separately in each 4 m patch so shifted plots still fit. Plants between rows are marked as possible weeds; where rows are not clear, nothing is marked. No spacing to type: the Count tab has one checkbox, Find crop rows. Found 91 cm on Tifton and Midville and 76 cm on IH corn; no rows on a closed canopy.
    4.5.0: The plant counter is back as a fast first count that you check and correct on the map. A count from a plant mask alone cannot tell every weed from the crop or separate overlapping plants, so the Count tab now has Add plant, Remove point, Plant or weed, Undo last and Done. Each click is saved and the count, plants per m2, the summary table and the counts per plot are updated at once. With a crop row spacing, plants between the rows are marked as possible weeds (grey with a red ring) and not counted, and any of them can be switched back.
    4.4.0: The plant counter goal was removed (brought back in 4.5.0 with corrections on the map).
    4.3.1: The plant counter counts plants, not leaves. Leaves of one plant that show as separate pieces (the stem or petiole between them is thin) are joined: pieces closer than 1 cm (setting Join leaves closer than) are one plant, after specks smaller than the smallest plant are dropped. On PhenoBench test images the share of plants counted exactly once rose from 72 to 88 (seedlings), 51 to 57 and 48 to 50, and split plants fell from 21 to 2, 19 to 6 and 12 to 5 (all in percent). The check flag now compares with the larger plants (2.5 x the 75th percentile). The plant points layer always sits at the top of the Layers panel: yellow dots of 3.8 mm with a black outline, orange for check.
    4.3.0: Three goals at the top of the panel: Plant mask, Plant counter, Training data for a model. Tabs 1 to 3 are the same for every goal; tab 4 is the goal's own step; Batch is last. (1) Count tab: one plant is one separate group of plant pixels of at least the smallest plant size (cm2) with a sure core (at least 5 pixels where every vote says plant), so soil spots let in by a low threshold are not counted. Big groups are flagged check. Optional crop row spacing leaves out plants between rows; optional plot file gives counts per plot; batch masks can be counted at once. Points layer PPE Plants and CSV tables. (2) Train data tab: image tiles with every band and PPE labels (plant, soil, unsure) for training a fast plant and soil model with no hand labelling, split into train and validation by image. (3) tools/ppe_train.py (outside QGIS, needs PyTorch): train, predict, check for drift against PPE's sure pixels, and update with new plus old images. (4) Faster runs: bands in one file are read together and decoded blocks are kept during a run (about twice as fast on compressed multiband images); results are identical.
    4.2.1: (1) Batch review on the Batch tab itself: Review selected opens the image on the map and shows its slider, threshold, canopy cover, Suggested, Finalize this mask and Next image right below the list, so there is no going back and forth; More on tab 3 opens What PPE found and crops for the same image. The list uses short checks (a warning sign for images to check, reviewed, mask written; hover a row for the details) and keeps its light colours when the computer is in dark mode. (2) RGB-only images: dark pixels are split by colour. Dark pixels whose strongest colour is still green are shown as shaded leaves (plant); the rest stay unclear (mostly soil in shadow). On PhenoBench (37 test images) about 98 percent of the dark green pixels at the seedling and middle stages were plant, and leaving out unclear now raises the overlap with hand labels at 0.70 from 84.5 to 87.3 (it lowered it to 81.2 before). Images with NIR are unchanged (vote and What PPE found identical on four fields). (3) Fixed: pure-black pixels in camera photos (deep shadow) showed as white holes on the map; they are now drawn black. An outside border of zeros (2 percent of the image or more) stays see-through.
    4.2.0: Batch: many images at once (tab 6). Choose a folder: every raster file in it is one image and every sub-folder with band files is one image. Run all runs them one after another exactly as on their own (same vote, suggested threshold, What PPE found, warnings and confident labels; one image failing does not stop the rest). The list shows each image's threshold, plant cover and checks, with images to check first on top. Review selected opens an image on tab 3 with the normal slider and What PPE found; its setting is kept when you open the next image (Next image on tab 3) and can be given to every image (Same settings for all). Finalize all masks writes every mask at its own threshold into the image's own folder, plus ppe_batch_summary.csv (threshold, plant cover, kinds left out, checks, mask and labels paths). A batch can be reopened later (Open a previous batch). Batch images from different UTM zones are each shown in their own coordinate system, and zooming to an image now works when the map uses another coordinate system.
    4.1.0: Two additions that work on any image; the vote and the mask are unchanged (bit for bit on five fields and 37 PhenoBench images). (1) Weak split warning: when PPE's top layer does not separate into two clear groups (Otsu separability under 0.65 on a 0 to 1 scale), the run summary, the message bar and the What PPE found card say so and suggest checking the mask. It fired on an RGB-only field and on PhenoBench seedling images, never on four multispectral fields or late-stage images. (2) Confident labels: every run also writes ppe_confident_labels.tif (1 plant where every voter agrees, 0 soil where at most a tenth of them say plant, 255 not labelled) for training a model or checking PPE. On PhenoBench a small U-Net trained on these labels alone reached 94.7 IoU on unseen images, against 95.4 with hand labels.
    4.0.0: Faint plants in sparse spots. Where the canopy is thin (under 25 percent plant in 3 m squares at the suggested threshold) small, pale plants get fewer votes; PPE marks the pixels a threshold 0.20 lower would add there and lists them on the What PPE found card with Add to the mask (the reverse of Leave out): the live preview adds them at once and keeps them whatever the slider, Finalize writes them in (ppe_plant_mask_..._with_sparse.tif) and reports the pixels added; the plot export has sparse_faint_pct and added_to_mask. On Tifton against its reference mask: IoU 91.3 to 91.9, canopy RMSE per 3 m cell 3.35 to 2.85 points, plant NDVI mean R2 0.83 to 0.92 and median 0.86 to 0.93. Bringing back faint pixels along detected crop rows was tested and did less, so rows are not used. Not offered with crop areas. What PPE found works on any image: every reference (green leaves' NDVI, colour, brightness and NIR; bare soil's NIR) is measured on the image from the pixels the voters agree on, leaf-side NDVI and colour cut-offs scale with this image's green leaves, each check runs whenever the image has its bands, a weak NIR band only drops the checks that compare NIR brightness (NDVI decides shaded or unclear), images without RGB measure darkness on NIR, camera RGB images get unclear (dark) pixels, and the card lists what could not be checked and why. Sparse spots are not marked when more than 30 percent of the squares are thin (the whole field is thin). Fixed: added faint plants were not drawn in the live preview. New kind dry or yellowing plant parts (brown), inside the canopy, can be left out like the others (dry_parts_pct). The vote is unchanged (bit for bit on four fields).
    3.9.0: What PPE found: a closed card on the Review tab lists, in one plain sentence each, plant parts that are not green (tassels, flowers; inside closed canopy only), leaf edges over soil (what looked like flowers in young corn), shaded leaves and unclear pixels, judged from the image's own leaves and bare soil and from where each pixel sits. Each can be left out of the mask and put back (Put all back): a tick takes those pixels out of the live preview at once (the same live layer, through a small VRT: nothing is copied) and they stay out whatever the sliders say; Finalize writes the mask without them to a file of its own and reports the pixels left out and the canopy before and after; the plot export and run record say what was left out. One magenta layer at a time: after Finalize the finalized mask, and once a slider moves or a kind is ticked the live preview again, with a note on the Export tab that its exports use the finalized mask. A long file path no longer widens the panel. Show them on the map adds a group with one layer per kind (plant parts amber, leaf edges light blue, shaded leaves blue, unclear red), so each kind can be switched on and off on its own; the card shows each kind's colour. PPE's layers come into the Layers panel folded. Nothing is judged when leaves and soil differ too little in near-infrared light. Results are now layers of their own in the Layers panel (plots, what PPE found, applied mask, image); only the live preview and crop outlines sit in the Plant Pixel Extractor group. Fixed: a note on the Image tab could be squeezed below one line after an image was removed, and the image-type list showed a tooltip that only repeated its own text. Several crops in one image. On the Review tab the user adds each crop and draws a rough outline around it on the map (click the corners, right-click to finish); each crop then gets its own threshold slider with its own canopy, the slider above sets the rest of the image, and the live preview shows every area at its own threshold. Finalize writes one mask with each area at its own threshold; the vote itself is unchanged, so segmentation is the same as before. The crop and the threshold used are added to each plot in the plot statistics. Optional information about the field (growth stage, planting and flight dates, soil moisture, weeds, notes) on the Image tab is saved with the results in ppe_run_record.json and the plot CSV files; at flowering or drying down the Review tab gives a threshold tip. The plot export shows its progress on the Plots tab. Band folders: when a folder is chosen, a dialog lists its raster files with a tick box, the band PPE recognised (which can be changed) and a note (thermal, stacked, unrecognised, a second file for the same band, different size); PPE imports only the ticked files, so stray files in the folder no longer cause errors. Choose band files reopens it. The dialog is readable in light and dark mode, shows full file names (the table scrolls sideways when they are long) and can be resized. A camera name inside a file name (for example MicaSense RedEdge) no longer decides the band: the band word nearest the end of the name does. Final clean-up: the panel has no settings to tune; the Reject pixels and Advanced settings cards are gone (shadow and algae guards always on, thresholds follow local conditions, four methods vote, sample 100000 pixels); the Folders and About this field sections stay. While a crop outline is drawn its button turns grey and reads Drawing, the other crops wait, and choosing another map tool ends the drawing. Faster on every computer with identical results: each band is read twice instead of three times, the full-resolution pass and the sampling run on several threads, and the number of blocks in memory is limited to a quarter of the RAM (Kritis 46 s to 20 s on 2 cores; vote, display and guard rasters bit-identical on four fields). Error messages are never blank: they name the step, the kind of error and the log file. True colour now keeps the real colour balance: red, green and blue share one stretch (before, each band was stretched on its own, which made soil grey-white and leaves cyan-green); the preview measures it on a wider grid of windows so it matches the image written by Run.
    3.8.0: Suggested threshold. After a run the slider starts at a threshold suggested for this image instead of a fixed 0.50: the value whose mask best matches the pixels that are at least half plant, estimated by mixing the image's own pure-plant and pure-soil spectra tile by tile (pale plots are judged against their own plants; pixels that are neither plant nor soil, such as algae and shade, are left out). The Review tab shows the suggestion and its good range, a button returns to it, and the threshold curve marks both. Tested against an independent plant mask (Tifton, whole field IoU 87.1 at 0.50 vs 91.3 suggested), an unmixing reference (IH, 71.5 vs 83.9) and labelled pixels (Kritis, unchanged at 100). Needs a NIR band; camera RGB images start at 0.50 and say why. Segmentation itself is unchanged. Plot statistics: plot files can be a Shapefile (choose the .shp or any of its side files), a zipped Shapefile or GeoPackage, GeoPackage, GeoJSON, KML/KMZ, GML, FlatGeobuf or SpatiaLite; the chosen plots appear on the map as 'PPE · Plots' with their IDs (labels can be switched off, the layer restyled like any QGIS layer) and the tab says how many lie over the image. The export now has canopy cover per plot (plot and plant pixels, canopy percent, plot and plant area in square metres) and, for every band and index, mean, median, SD, CV, min, P10, Q25, Q75, P90 and max of the plant pixels.
    3.7.7: Release clean-up for the QGIS plugin repository. The bright-neutral rejection raster is no longer added to the Layers panel (it stays in the run folder with the other guard diagnostics), so the map holds only the image, the live preview and the applied mask. Unused code removed; errors that were silently ignored are now written to the log. Segmentation unchanged.
    3.7.6: Image type is detected from the bands actually found, not from the band count. A 3-band NIR/red-edge/red file (or folder) is now reported as multispectral, not RGB; the Auto-detect entry names what was found (e.g. 'Auto-detect · Multispectral · 3 bands') and the note lists the bands and how the image is shown. A 3-band file with no band names asks for its band order, which now also offers NIR, red edge, red and NIR, red, green (colour-infrared camera). Segmentation unchanged.
    3.7.5: Robust across sensors, crops and growth stages. (1) Shaded leaves stay plant: the shadow guard now keeps dark pixels whose NDVI (and NDRE, when there is a red-edge band) is at plant level, which matters in dense late-season canopies (tested on Kritis, 8 Aug 2025: shaded leaf kept 76.5 percent -> 99.8 percent, no extra soil). (2) Camera (RGB-only) images get a colour guard: a pixel stays plant only if it is greener than the soil's own colour, so vehicles, tarps and grey residue are no longer called plant; a warning appears when plants and soil have almost the same colour. (3) Band names from MicaSense, Sequoia (GRE/RED/REG/NIR), DJI (MS_G/MS_R/MS_RE/MS_NIR) and wavelength names (e.g. 717nm) are recognised; thermal bands (LWIR, TIR, thermal, temperature) are ignored instead of being mistaken for a reflectance band. Framework unchanged (spread-ranked layers; Otsu, CDF, k-means, multi-Otsu vote).
    3.7.4: Changing the image is safe and clean. (1) Browsing for a new image when one is already chosen, switching the source type, or removing an image asks for confirmation first. (2) A new image starts everything afresh: results, slider, summaries, log, export and plot settings, and the old PPE layers are cleared. (3) A remove button (✕) beside each image path takes the image out of PPE and off the map. (4) The panel follows the map: deleting the PPE image layer in the Layers panel resets PPE; deleting the live-preview layer switches the slider off with a note. (5) The image cannot be changed while PPE is running. Segmentation unchanged.
 3.7.3: Panel layout redone and checked in QGIS 3.34 at three panel widths. Labels sit above their fields; drop-downs, number boxes and tick boxes are fully drawn (no half-drawn arrows or clipped boxes); every section is a card, including Advanced settings and Folders; messages grow with their text instead of being cut off; the run summary is short (details stay in the log); every tab scrolls; the Export tab's progress bar only shows exports. Segmentation unchanged.
 3.7.2: Workflow and appearance. (1) The image is shown on the map as soon as it is chosen, before Run: true colour when red, green and blue exist; false colour (NIR, red, green) when one of them is missing; otherwise the NIR band in grey. The first tab says what is shown and which bands were found. Run keeps the image on the map while it works. (2) The panel's styling now appears inside QGIS; before, it was attached where QGIS ignores it and the panel showed in the plain default look. (3) Images drawn straight from a reflectance file are no longer black (the colour stretch was not being applied).
 3.7.1: Fixes found on a second real field (IH, dense canopy). (1) The all-soil / all-canopy check no longer overrides the mask; in 3.6.0 and 3.7.0 it set the whole IH field to 100 percent canopy. It now only warns, with a stricter rule. (2) Algae guard floor lowered from a third to a quarter of the soil-to-plant red-edge rise, measured from the barest soil; the old floor removed pale plants in sparse plots. (3) The CDF knee is now repeatable: extreme pixels are ignored and, when the curve has two knees of similar strength, both are used with half a vote between them. Before, the same image could give two different thresholds. (4) Thresholds follow local conditions again (Advanced settings; can be switched to one set for the whole field). (5) Optional fifth method, half-mixture, off by default.
 3.7.0: Back to the original PPE framework, with repairs. (1) Layers are ranked by spread again, now measured without units, with one normalised-difference index per spectral group and the top three voting. (2) Each layer is split by Otsu, CDF knee, k-means and multi-Otsu; every layer x method result is one equal vote (12 votes). (3) Algae guard rewritten as one rule: a plant must show NDRE above bare-soil level; on the Tifton test field algae counted as plant fell from 58 percent of labelled algae pixels (3.6.0) to 0 percent. (4) Shadow guard restored to its 3.5.0 behaviour. (5) Removed from 3.6.0: half-mixture threshold, red-edge/red forced as a fourth layer, tiled thresholds. Kept from 3.6.0: all-soil / all-canopy check, single image read, bug fixes, panel layout. (6) SciPy is no longer needed.
 3.6.0: Segmentation accuracy and speed. (1) Only ratio indices vote (NDVI, NDRE, GLI, red-edge/red), so shaded leaves keep their class and results do not depend on reflectance scale. (2) Each index is split by Otsu and by a half-mixture threshold that marks a pixel half covered by plant. (3) Images that are all soil or all canopy are detected instead of being split in two. (4) Shadow guard judges vegetation by NDVI; algae guard uses a scale-free red-edge rule and is skipped without a red-edge band. (5) Fixed: red/green ratio polarity, bed-ridge units, plot statistics on images without a CRS. (6) The image is sampled once instead of three times. (7) Panel layout: all five tabs fit, no sideways scrolling, advanced settings and folders fold away.
