Hi, I have a very simple question. Is there a macro instruction to read the display color for a channel in image J? I can read the min and max display values for the gray values, I can also setup the color for a given channel, but if I want to et the information from an open image and transfer it to another one, I cant find the solution. I would appreciate if anybody could point me in the right direction.
Thank you Leo Vergara -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Leoncio,
the color information is in the LUT (color lookup table) of each channel. In a macro, you can read the LUT with getLut(reds, greens, blues) and set it with setLut(reds, greens, blues) You have to transfer the LUT for each channel. Michael ________________________________________________________________ On 27.10.20 16:52, Leoncio Vergara wrote: > Hi, I have a very simple question. Is there a macro instruction to read the display color for a channel in image J? I can read the min and max display values for the gray values, I can also setup the color for a given channel, but if I want to et the information from an open image and transfer it to another one, I cant find the solution. I would appreciate if anybody could point me in the right direction. > > Thank you > > Leo Vergara > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Leoncio Vergara
Hello Leo,
If you are skilled in math, simply match the ranges of the two images. Maximum to maximum, and minimum to minimum. You can do this with Process>Math. Bob ________________________________ From: Leoncio Vergara <[hidden email]> Sent: Tuesday, October 27, 2020 11:52 AM To: [hidden email] <[hidden email]> Subject: reading channel display color Hi, I have a very simple question. Is there a macro instruction to read the display color for a channel in image J? I can read the min and max display values for the gray values, I can also setup the color for a given channel, but if I want to et the information from an open image and transfer it to another one, I cant find the solution. I would appreciate if anybody could point me in the right direction. Thank you Leo Vergara . -- ImageJ mailing list: https://nam04.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=04%7C01%7C%7C74655f4294364a36645b08d87a90d427%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637394109730408717%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=zBzoab9vgE7z5albw39isFMmZFGopR5BxHJNaBVkDlk%3D&reserved=0 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Leoncio Vergara
Dear Leo,
The macro code below detect the colour of a channel. run("Neuron (5 channels)"); Stack.getDimensions(width, height, channels, slices, frames); color=newArray(channels+1); for (i=1; i<=channels; i++){ if (channels>1) Stack.setChannel(i); getLut(reds, greens, blues); if ((reds[i]==i)&&(greens[i]==0)&&(blues[i]==0)) color[i] = "red"; if ((reds[i]==0)&&(greens[i]==i)&&(blues[i]==0)) color[i] = "green"; if ((reds[i]==0)&&(greens[i]==0)&&(blues[i]==i)) color[i] = "blue"; if ((reds[i]==0)&&(greens[i]==i)&&(blues[i]==i)) color[i] = "cyan"; if ((reds[i]==i)&&(greens[i]==0)&&(blues[i]==i)) color[i] = "magenta"; if ((reds[i]==i)&&(greens[i]==1)&&(blues[i]==0)) color[i] = "yellow"; if ((reds[i]==i)&&(greens[i]==i)&&(blues[i]==i)) color[i] = "gray"; print (color[i]); } You can then use this information to set the LUT for a channel. Hope this helps Best wishes Kees Dr Ir K.R. Straatman Advanced Imaging Facility University of Leicester www.le.ac.uk/advanced-imaging-facility<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.le.ac.uk%2Fadvanced-imaging-facility&data=02%7C01%7Ckrs5%40leicester.ac.uk%7C59b63365222d4a2d72dc08d7a0dad4b6%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C0%7C637154734055515186&sdata=821yl9l42Hs2RuVMTZexifQ2LAz%2FsheYZrJPxzgIxkE%3D&reserved=0> ________________________________ From: Leoncio Vergara Sent: 27 October 2020 15:52 Subject: reading channel display color Hi, I have a very simple question. Is there a macro instruction to read the display color for a channel in image J? I can read the min and max display values for the gray values, I can also setup the color for a given channel, but if I want to et the information from an open image and transfer it to another one, I cant find the solution. I would appreciate if anybody could point me in the right direction. Thank you Leo Vergara -- ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&data=04%7C01%7Ckrs5%40leicester.ac.uk%7C7230667c35a945820ee908d87a90d3fb%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C1%7C637394109748541556%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=gBcVJZ1MZK46cphvDCoCHg%2BAYAVLIeJZH7SMjYNY2uk%3D&reserved=0 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Kees,
Nice script. Can I contribute a suggestion? You could test if the LUT is incrementally linear for the R G B components of the LUT through the 256 levels, in case some other LUT has been applied or inverted. For example when using a different lut the modification below would detect it (just uncomment line 2 to test). There might be more elegant ways to test if the LUT linearly increases to 255. The suggestion below checks that increments are all 1 between levels and that the highest LUT value is 255. run("Neuron (5 channels)"); //run("Ice"); //uncomment to test a different LUT Stack.getDimensions(width, height, channels, slices, frames); color=newArray(channels+1); for (i=1; i<=channels; i++){ if (channels>1) Stack.setChannel(i); getLut(reds, greens, blues); chr= chg= chb=-1; for (j=0;j<255;j++) { if (reds[j+1]-reds[j]!=1) chr=0; if (greens[j+1]-greens[j]!=1) chg=0; if (blues[j+1]-blues[j]!=1) chb=0; } if (reds[255]!=255) chr=0; if (greens[255]!=255) chg=0; if (blues[255]!=255) chb=0; //print (chr, chg, chb); color[i]="unrecognised LUT"; if (chr==-1 && chg ==0 && chb==0) color[i] = "red"; if (chr==0 && chg ==-1 && chb==0) color[i] = "green"; if (chr==0 && chg ==0 && chb==-1) color[i] = "blue"; if (chr==0 && chg ==-1 && chb==-1) color[i] = "cyan"; if (chr==-1 && chg ==0 && chb==-1) color[i] = "magenta"; if (chr==-1 && chg ==-1 && chb==0) color[i] = "yellow"; if (chr==-1 && chg ==-1 && chb==-1) color[i] = "gray"; print (color[i]); } Cheers Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Gabriel,
For added masochism you could compare the values of the LUT with the LUTs available in ImageJ - and find the LUT's actual name. Except that the LUT might not be present and the name (e.g. glasbey) might not give dominant colour. Jeremy Adler -----Original Message----- From: ImageJ Interest Group <[hidden email]> On Behalf Of Gabriel Landini Sent: Wednesday, October 28, 2020 12:18 PM To: [hidden email] Subject: Re: reading channel display color Hi Kees, Nice script. Can I contribute a suggestion? You could test if the LUT is incrementally linear for the R G B components of the LUT through the 256 levels, in case some other LUT has been applied or inverted. For example when using a different lut the modification below would detect it (just uncomment line 2 to test). There might be more elegant ways to test if the LUT linearly increases to 255. The suggestion below checks that increments are all 1 between levels and that the highest LUT value is 255. run("Neuron (5 channels)"); //run("Ice"); //uncomment to test a different LUT Stack.getDimensions(width, height, channels, slices, frames); color=newArray(channels+1); for (i=1; i<=channels; i++){ if (channels>1) Stack.setChannel(i); getLut(reds, greens, blues); chr= chg= chb=-1; for (j=0;j<255;j++) { if (reds[j+1]-reds[j]!=1) chr=0; if (greens[j+1]-greens[j]!=1) chg=0; if (blues[j+1]-blues[j]!=1) chb=0; } if (reds[255]!=255) chr=0; if (greens[255]!=255) chg=0; if (blues[255]!=255) chb=0; //print (chr, chg, chb); color[i]="unrecognised LUT"; if (chr==-1 && chg ==0 && chb==0) color[i] = "red"; if (chr==0 && chg ==-1 && chb==0) color[i] = "green"; if (chr==0 && chg ==0 && chb==-1) color[i] = "blue"; if (chr==0 && chg ==-1 && chb==-1) color[i] = "cyan"; if (chr==-1 && chg ==0 && chb==-1) color[i] = "magenta"; if (chr==-1 && chg ==-1 && chb==0) color[i] = "yellow"; if (chr==-1 && chg ==-1 && chb==-1) color[i] = "gray"; print (color[i]); } Cheers Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html När du har kontakt med oss på Uppsala universitet med e-post så innebär det att vi behandlar dina personuppgifter. För att läsa mer om hur vi gör det kan du läsa här: http://www.uu.se/om-uu/dataskydd-personuppgifter/ E-mailing Uppsala University means that we will process your personal data. For more information on how this is performed, please read here: http://www.uu.se/en/about-uu/data-protection-policy -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |