(Quick note upfront: English isn't my first language, so I use an LLM to help with editing and translation. The research, data collection, and experiments are my own*.)*
In Part 1, I shared how my v1 parasite egg detector got 97% accuracy on public benchmarks and completely fell apart on unseen microscope slides.
Since public datasets were mostly human parasites, poorly labeled, or tiny (30–40px), I decided to build a clean v2 dataset from scratch: standardized 640×640 tiles, grayscale + CLAHE, and a strict minimum size of 80px on the shortest side so morphological details actually survive.
Here is how I sourced the data, built my own labeling tools, and engineered a deterministic compositing pipeline to fill the data gap.
1. Where do you find parasite eggs when Kaggle fails you?
My goal was 500 samples per class across 13-14 veterinary species (Toxocara, Ancylostoma, Cystoisospora, Ascaris, Dipylidium, Hymenolepis, Taenia, Toxascaris, Trichuris, Capillaria, Opisthorchis, Giardia, Eimeria). Reality check: hitting ~150 real images per class was a massive win.
- Academic papers & Reddit: Dead ends. Papers rarely share datasets, authors rarely reply, and asking on niche subreddits got me ~50 images and a couple of bans.
- Google Images & YouTube: Mostly duplicates, low-res thumbnails, or talking-head videos. Plus, searching the open web for veterinary parasites means every 5th photo is literal (bloody)feces or worms coming out of a puppy - after a few weeks, cooking spaghetti started triggering weird flashbacks.
- The unexpected goldmine - Instagram: Vet techs and parasitologists love posting microscope finds under Latin species hashtags, along with panning videos of slides. Scrubbing through slide-panning videos lets you grab dozens of unique, non-duplicate crops. Fun fact: ~25% of my Dipylidium packets came from a lab video with a dancing guy meme overlaid on top.
To speed this up, I wrote browser bookmarklets to pop full-res images into new tabs so I could quickly filter out anything below 80px.
Funny side effect of this grind: when I started, all parasite eggs looked identical to me - like looking at the night sky when someone points out planets and constellations, and all you see are random white dots. While scrolling through vet accounts, I kept running into "guess the parasite" quizzes posted by lab techs. At first, I had no clue. After staring at thousands of slides, I caught myself solving those quizzes just from tiny feed thumbnails without even opening the full image.
2. Harvesting clean negative tiles from large slides
To stop the detector from hallucinating eggs on yeast, pollen, fat droplets, and plant fibers, 15 - 20% of the training set needed to be pure negative 640×640 tiles. Since you can't search for "empty fecal smear," I harvested 5 - 6 clean 640×640 background tiles from the empty 80–90% space around labeled eggs in large frames (like Chula's 3000px images), enforcing a strict ≤15% overlap limit. This gave me both hard negative tiles and real microscopy canvases for synthetic compositing.
To make the negatives even tougher, I also pulled in a couple of public pollen grain microscopy datasets and mixed selected tiles into the negative pool - pollen is notorious in vet labs for mimicking the exact size, round shape, and wall thickness of real parasite eggs. Together, this gave me both hard negative tiles and real microscopy canvases for synthetic compositing.
3. Ditching CVAT for a custom Flash 5-style labeling tool
Generic tools like CVAT kill your rhythm when doing thousands of domain-specific actions. Since I come from web dev, I built my own keyboard-first UI:
- Hotkeys for everything: One key drops a
640×640 positive crop, another drops a negative background crop, another zooms 200% and centers on tiny eggs. - MobileSAM/GrabCut + Catmull-Rom splines: Pulling Bezier control handles in standard tools drove me crazy. Inspired by my old Macromedia Flash 5 days, I initialized masks with MobileSAM/GrabCut and refined them using Catmull-Rom splines - you just drop points along the egg's shell, and the curve bends smoothly through them.
4. Deterministic compositing pipeline (bridging 150 → 500 samples)
To scale from ~150 real samples up to 500 per class without creating obvious "sticker" artifacts, I built a deterministic compositing pipeline with strict leakage controls:
- Strict split isolation: Donors (cut-out eggs) and background canvases are split by original slide/video/source first. Synthetic images are generated strictly for the
train set - donors never cross into val or test, and repeated pastes aren't treated as independent validation samples. - Pre- & post-mask processing: Raw masks go through manual refinement, followed by a
2px erosion (to strip away the donor's original background halo) and a 5×5 Gaussian alpha feathering so the model can't cheat by detecting sharp cut-out edges. - Local color/brightness matching + CLAHE: Before pasting, the donor's local luminance and color statistics are matched to the target background region, followed by random rotation/scaling and final
grayscale + CLAHE normalization so the pasted egg shares the exact sensor noise and contrast profile of the host slide. - Simulating microscope Z-axis depth of field (DOF): Even though microscope photos are 2D, the physical sample is a 3D fluid layer between slides (or inside a McMaster/Mini-FLOTAC chamber). Because microscope objectives have a razor-thin depth of field, one egg floating near the coverslip can be tack-sharp while another suspended slightly deeper is out of focus. Applying selective defocus/Gaussian blur only to the masked egg cutout (while keeping the surrounding background sharp) lets me simulate real Z-axis focal plane shifts. (Note: To make sure the detector doesn't learn a shortcut like "blurry blob = egg," I'm also preparing an experiment to apply the same localized blur to confirmed hard negatives like pollen and debris).
Next up: moving into actual training on RunPod, running controlled ablations (real-only vs. real + synthetic), and seeing how the v2 model holds up on unseen camera setups.
For those who've used copy-paste synthesis in medical/microscopy CV: Did soft alpha feathering + local luminance matching prevent boundary overfitting for you, or did your models still find ways to cheat?