Analysing size of butterfly wings

fiji
imagej

#1

Hi there,

I need to measure wing size for >1000 tropical butterflies.

My macro script has worked for some species but not others - wings which are irridescent/have bright colour patches are proving particularly difficult and I’m struggling to find a way of removing the background without deleting any wing.

Eg. scripts and images below. I’ve been trying to fix this problem for several days now so any help would be HUGELY appreciated!!

(I’ll apologise in advance for the quality of Images - we took them in the field and equipment/lighting conditions were basic!)

---------MACRO SCRIPT--------

//set scale
makeLine(1320, 3282, 1436, 3288);
run("Set Scale...", "distance=116.1551 known=5 pixel=1 unit=mm global");

//select wing
makeRectangle(272, 0, 2016, 1616);
run("Crop");

//adjust image to improve wing detection
//have tried adjusting several parameters, unfortunately with no luck

//OPTION 1
run("Color Balance...");
setMinAndMax(60, 90);

//...OR OPTION 2
run("Options...", "iterations=15 count=3 pad");
run("Enhance Contrast...", "saturated=0.3");

//...OR OPTION 3
run("Color Threshold...");

//remove background/fill holes
setOption("BlackBackground", false);
run("Make Binary");
run("Close-");
run("Fill Holes");
run("Close-");
run("Fill Holes");

//get area
run("Set Measurements...", "area fit shape feret's limit add display redirect=None decimal=3");
run("Analyze Particles...", "size=200-Infinity show=Outlines display include summarize record");

Cheers team!

Tish
Original image

Effects of OPTION1 edits (surely theres a way to remove the orange background?!!)

Output from macro


#2

Hi Tish,

It’s probably because you are using the HSV color space, you could try RGB, here is a macro that work (just after you crop your image):

min=newArray(3);
max=newArray(3);
filter=newArray(3);
a=getTitle();
run("RGB Stack");
run("Convert Stack to Images");
selectWindow("Red");
rename("0");
selectWindow("Green");
rename("1");
selectWindow("Blue");
rename("2");
min[0]=81;
max[0]=255;
filter[0]="pass";
min[1]=74;
max[1]=255;
filter[1]="pass";
min[2]=17;
max[2]=255;
filter[2]="pass";
for (i=0;i<3;i++){
  selectWindow(""+i);
  setThreshold(min[i], max[i]);
  run("Convert to Mask");
  if (filter[i]=="stop")  run("Invert");
}
imageCalculator("AND create", "0","1");
imageCalculator("AND create", "Result of 0","2");
for (i=0;i<3;i++){
  selectWindow(""+i);
  close();
}
selectWindow("Result of 0");
close();
selectWindow("Result of Result of 0");
rename(a);

Alternatively you could also try the color clustering in Fiji > plugins > segmentation.

Hope this help.

Best,

Cedric


#3

Hey,

I was curious about this and tried Cedric’s suggestion with the color clustering. After trying around with the parameters for 5 min (on the orange image), it already works pretty well:

Thanks for pointing out this plug in!


#4

This is SUPER helpful, thank you so much for your help!!

What part of this script do you reccommend I edit to make it suitable for different butterflies? It seems to be working very well for the genera archaeoprepona (butterfly above), but poorly for morphos (image attached)…?? :thinking:


#5

Hi Tish,

I just played with the RGB color and save what I did with the macro recorder in the color threshold.

You should take a look at the documentation.
Cedric


#6

Great, thanks very much for your help!