Assign 8bit values to an image?

binarize

#1

I have some images of tree canopies which I want to analyse in a software.
The software requires that the images be 8bit with three values:
0 = vegetation
100 = sky
255 = mask (i.e. area of image not to analyse)

I can binarize my images which gives me 0 and 255 values (for veg or sky) but I cant figure out how to make the sky parts 100 and then I want to add a mask manually by drawing but how do I assign this 255?

I want to mask the part where the trunk was in the original photo, because the software will class this as a very large gap in the canopy, which it isnt, hence the need to mask it before analysis

24_2|nullxnull

24_2|nullxnull


#2

Good day,

please post the original (color) image and explain what is to be masked.

Regards

Herbie


#3

This ImageJ-macro will get you started:

// imagej-macro "canopy" (Herbie G., 08. Nov 2018)
requires( "1.52h" );
setBatchMode(true);
w=getWidth();
h=getHeight();
if (w>h) exit("Image is assumed portrait oriented.");
run("Duplicate...", "title=O");
setBackgroundColor(0, 0, 0);
doWand(w*0.5, 0, 10.0, "Legacy");
run("Clear");
doWand(w*0.5, h-1, 10.0, "Legacy");
run("Clear");
run("Canvas Size...", "width="+h+" height="+h+" position=Center zero");
doWand(0, h*0.5, 0, "Legacy");
run("Fit Circle");
run("Crop");
run("RGB to CMYK");
run("Stack to Images");
setAutoThreshold("Intermodes no-reset");
setOption("BlackBackground", true);
run("Convert to Mask");
close("M");close("C");close("O");
selectImage("Y");
run("Grays");
run("8-bit");
run("Restore Selection");
changeValues(0, 0, 155);
changeValues(0, 154, 255);
changeValues(156, 255, 255);
imageCalculator("Min", "Y","K");
close("K");
run("Invert");
setBackgroundColor(255, 255, 255);
run("Clear Outside");
run("Select None");
setBatchMode(false);
exit();
// imagej-macro "canopy" (Herbie G., 08. Nov 2018)

Paste the above macro code to an empty macro window (Plugins >> New >> Macro) and run it with your original color-image open in ImageJ.

The macro requires that the imageJ-plugin “RGB_to_CMYK” is installed.

With your sample image I get:

Finally, please refrain from using JPG-compressed images for scientific work.
JPG-compression introduces artifacts that can’t be removed!
(Converting a JPG-compressed image to TIFF- or PNG-format doesn’t make sense.)

HTH

Herbie


#4

Ah thanks.
It was the changeValues part of the macro that I needed.