Hi all,
I am having trouble setting auto brightness/contrast in a macro. After a thorough search on the web and after looking at the macro recorder, it appears that the only command line to replace the manual click of the "Auto" button in the Brightness/Contrast window is the following : run("Enhance Contrast", "saturated=0.35"); However, I may be wrong but this looks like a different command to me. While the "Enhance Contrast" command appears to just modify the upper limit of the histogram (e.g. Max=98 out of 256), it seems that the "Auto Brightness/Contrast" command changes both limits of the histogram (e.g. Min=23, Max=98). Also, I did note that when thresholding the two images I get different results depending on the command. Hence my first question: is this just a wrong impression or is there indeed a difference between the two commands? If this is true, then my second question is: how to implement that "Auto Brightness/Contrast" command in a macro? Obviously there is the setMinAndMax() function, but the problem is this can't be set to "auto"? In other words, I would like to use the script behind that "Auto" button in the Brightness/Contrast window, with a command line in a macro. Thank you so much, |
On Fri, May 11, 2012 at 5:20 PM, Damien <[hidden email]> wrote:
> Hi all, > > I am having trouble setting auto brightness/contrast in a macro. After a > thorough search on the web and after looking at the macro recorder, it > appears that the only command line to replace the manual click of the "Auto" > button in the Brightness/Contrast window is the following : > > run("Enhance Contrast", "saturated=0.35"); > > However, I may be wrong but this looks like a different command to me. While > the "Enhance Contrast" command appears to just modify the upper limit of the > histogram (e.g. Max=98 out of 256), it seems that the "Auto > Brightness/Contrast" command changes both limits of the histogram (e.g. > Min=23, Max=98). Also, I did note that when thresholding the two images I > get different results depending on the command. > > Hence my first question: is this just a wrong impression or is there indeed > a difference between the two commands? > > If this is true, then my second question is: how to implement that "Auto > Brightness/Contrast" command in a macro? Obviously there is the > setMinAndMax() function, but the problem is this can't be set to "auto"? In > other words, I would like to use the script behind that "Auto" button in the > Brightness/Contrast window, with a command line in a macro. > > Thank you so much, > > -- Hi Damien, I had the same question before by myself but did not explore the secret at that time. It's a good chance seeing your post so I checked the source. Here is the explanation of how the lower and upper values are calculated. http://cmci.embl.de/documents/120206pyip_cooking/python_imagej_cookbook#automatic_brightnesscontrast_button So the 'Auto' button in the GUI is indeed different compared to the "Enhance Contrast" by saturation of 0.35. In the above link, I rewrote the original Java code in Jython but I realize that this is doable in a much shorter way using ImageJ macro simply by using getRawStatistics(nPixels, mean, min, max, std, histogram) command. Cheers, Kota -- ------------------------------------------------------------- Dr. Kota Miura Scientist & IT Engineer Centre for Molecular and Cellular Imaging, European Molecular Biology Laboratory Meyerhofstr. 1 69117 Heidelberg GERMANY Tel +49 6221 387 404 Fax +49 6221 387 512 http://cmci.embl.de ------------------------------------------------------------- |
Hi Kota, Thanks a lot for your reply. This should definitely help. I will have a look at your link ASAP and let you know how it worked for me. Cheers,
Damien Guimond, PhD Student Mediterranean Institute of Neurobiology (Inmed) - Inserm U901 - Aix-Marseille Université (AMU) - France http://www.inmed.univ-mrs.fr/index.php?page=26&id=188 +33 4 91 82 81 29 Dept of Veterinary & Comparative Anatomy, Pharmacology & Physiology (VCAPP) - Washington State University (WSU) - WA, USA http://waymanlab.org/ +1 (509) 335-8211 |
In reply to this post by Kota Miura
Hi guys,
Based on Kota Miura's post and code, I tried to reproduce the autoAdjust function in ImageJ Macro language. Here it is below. Sorry in advance for all the mistakes I did, I am not familiar with coding. Please don't hesitate to correct/improve the script. As far as differences with the original function (not an exhaustive list): - it should work for 8-bit images only; - for some reason it doesn't work if you repeat the macro several times in a row. - the last command will modify the actual image's histogram, so be sure to duplicate your image or to remove that line if you want to modify the display only.
|
In reply to this post by Kota Miura
Dear All,
I'd really appreciate if you could make potential candidates aware of the position advertised below. It is not directly an ImageJ related issue (my excuse for that) but certainly very much linked to it. Thanks Gabor Head of the Data Analysis Unit for Light Microscopy and High Throughput Screening The Light Microscopy and Screening Centre (LMSC) of the ETH Zurich is one of the leading academic core facilities in Switzerland offering access to high-end microscopy and high-throughput screening instrumentation. Currently we have ~ 250 users mostly coming from the biology but including researchers also from physics, material science etc. Besides experimental instrumentation, the LMSC operates a number of image processing computers with various commercial and custom software packages. Being not only a service unit, the LMSC performs active research in various imaging related fields often in close collaboration with the different ETH departments (biology, computer science, engineering etc.) Due to strongly increasing demand, the LMSC will set up a new unit in order to support its users on the field of data analysis, covering biological image processing, instrument control, image-based modelling and simulation, data processing for high-throughput screening covering the complete analysis pipeline, also including classification, hit definition, statistical evaluation, maintaining screening databases and related bioinformatics tasks. Central mission of the Data Analysis Unit is to provide comprehensive service for the users of LMSC, including basic education and training in using various software tools and packages, helping to adapt existing and develop customized tools for solving individual data analysis problems as well as maintain joint research efforts aiming at developing new methods on areas of strategic importance for the LMSC community. We are looking for a scientist with proven research and/or service track on at least some of the fields mentioned above. S/he is expected to actively participate in and oversee the service and training activities (the primary function of the unit) while upon availability of resources also initiate research projects in close collaboration with LMSC users and supervise the participating Master´s and PhD students. S/he should start the operation of the unit immediately while building up the group to full-scale operation within the next 2 years, including recruiting further staff member(s) and fundraising for financing long-term development efforts. The suitable candidate is having a PhD degree in Computer Science/Physics/Biology or related field. Experience with ImageJ (Java) or Matlab is expected, C++, R and scripting is of advantage. Knowledge of databases and bioinformatics tools is a strong plus. Good communication skills (solid English knowledge) and willingness to participate in teaching activities at quite different levels are essential. Initial contract will be offered for one year but can be prolonged with a possibility of permanent employment. The ETH Zurich offers cutting-edge infrastructure, highly international environment and excellent working conditions. Please send your CV + publication list, including a short description of your current research interests and the name/address of potential references (in electronic format) to: Daniela Tschümperlin; [hidden email] Further information is available on www.lmc.ethz.ch <http://www.lmc.ethz.ch <http://www.lmc.ethz.ch/>> or contact Dr. G. Csucs ([hidden email]). |
In reply to this post by Damien
On Wed, May 16, 2012 at 2:43 PM, Damien <[hidden email]> wrote:
> Hi guys, > > Based on Kota Miura's post and code, I tried to reproduce the autoAdjust > function in ImageJ Macro language. Here it is below. Sorry in advance for > all the mistakes I did, I am not familiar with coding. Please don't hesitate > to correct/improve the script. > > As far as differences with the original function (not an exhaustive list): > - it should work for 8-bit images only; > - for some reason it doesn't work if you repeat the macro several times in a > row. > - the last command will modify the actual image's histogram, so be sure to > duplicate your image or to remove that line if you want to modify the > display only. > > > >> >> macro "autoAdjust" { >> /* >> * rewriting "Auto contrast adjustment" button of "Brightness/Contrast" >> * Damien Guimond >> * 20120516 >> * Acknowledgements: Kota Miura >> */ >> >> AUTO_THRESHOLD = 5000; >> >> getRawStatistics(count, mean, min, max, std); >> limit = count/10; >> threshold = count/AUTO_THRESHOLD; >> >> nBins = 256; >> getHistogram(values, counts, nBins); >> >> i = -1; >> condition = 0; >> while (condition != 1) { >> i = i+1; >> count = counts[i]; >> if (count > limit) { count = 0; } >> found = count > threshold; >> if (found) { condition = 1; } >> else if (i >= 255) { condition = 1; } >> } >> hmin = i; >> >> i = 256; >> condition = 0; >> while (condition != 1) { >> i = i-1; >> count = counts[i]; >> if (count > limit) { count = 0; } >> found = count > threshold; >> if (found) { condition = 1; } >> else if (i < 1) { condition = 1; } >> } >> hmax = i; >> >> setMinAndMax(hmin, hmax); >> run("Apply LUT"); >> } >> >> >> >> >> >> Hi Damien, Great! I tested your macro and it works well with 8-bit images. I found that it has problem when dealing with 16-bit images so I modified your macro, which now gives the same enhancements of 16-bit image like the "auto" button in the brightness/contrast GUI. Cheers, Kota ---- AUTO_THRESHOLD = 5000; getRawStatistics(pixcount); limit = pixcount/10; threshold = pixcount/AUTO_THRESHOLD; nBins = 256; getHistogram(values, histA, nBins); i = -1; found = false; do { counts = histA[++i]; if (counts > limit) counts = 0; found = counts > threshold; } while ((!found) && (i < histA.length-1)) hmin = values[i]; i = histA.length; do { counts = histA[--i]; if (counts > limit) counts = 0; found = counts > threshold; } while ((!found) && (i > 0)) hmax = values[i]; setMinAndMax(hmin, hmax); //print(hmin, hmax); run("Apply LUT"); -- ------------------------------------------------------------- Dr. Kota Miura Scientist & IT Engineer Centre for Molecular and Cellular Imaging, European Molecular Biology Laboratory Meyerhofstr. 1 69117 Heidelberg GERMANY Tel +49 6221 387 404 Fax +49 6221 387 512 http://cmci.embl.de ------------------------------------------------------------- |
Free forum by Nabble | Edit this page |