Skip to content

Instantly share code, notes, and snippets.

# lacan/lutToIntensity.ijm Last active Jul 24, 2019

Reconvert color coded image to intensity based on color scale. #ImageJ #Fiji #Macro
 /* * Reconvert color LUT to intensity * Olivier BURRI * BioImaging and Optics Platform BIOP, EPFL * In reply to an ImageJ Forum Post http://forum.imagej.net/t/split-colored-height-map-of-moon-in-greyscale-images/ * Provided As-Is */ // Before running this macro, make sure that you have an image called LUT with the color scalebar separately // Keep original image reference ori = getTitle(); // Build LUT selectImage("LUT"); getDimensions(lw,lh,lc,lz,lt); makeLine(lw/2,0,lw/2,lh); getSelectionCoordinates(x,y); lut = newArray(y[1]-y[0]+1); k=0; for(j=round(y[0]);j>16)&0xff; // extract red byte (bits 23-17) valgreen = (val>>8)&0xff; // extract green byte (bits 15-8) valblue = val&0xff; // extract blue byte (bits 7-0) minD = 99999999999; for(i=0; i>16)&0xff; // extract red byte (bits 23-17) lutgreen = (lut[i]>>8)&0xff; // extract green byte (bits 15-8) lutblue = lut[i]&0xff; // extract blue byte (bits 7-0) // Get euclidean distance deltargb = sqrt((valred - lutred)*(valred - lutred) + (valgreen - lutgreen)*(valgreen - lutgreen) + (valblue - lutblue)*(valblue - lutblue)); // Keep minimum value if(deltargb < minD) { minD = deltargb; minI = i; // If 0 then we hav ethe exact match already if(deltargb == 0) return minI; } } return minI; }

### fedebenelli commented Jul 24, 2019 • edited

 Probably I misunderstood something in the description, but I'll like to add that I had to change the `makeLine(lw/2,0,lw/2,lh)` to `makeLine(lw*9/10,0,lw*9/10,lh)` in line 17, because that's were my scalebar was. Thanks for the Macro! It really saved me from a lot of headaches
to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.