{"id":1856,"date":"2024-06-05T19:22:41","date_gmt":"2024-06-05T23:22:41","guid":{"rendered":"http:\/\/wordpress.forensicpath.us\/?p=1856"},"modified":"2024-06-05T19:22:41","modified_gmt":"2024-06-05T23:22:41","slug":"taking-and-processing-photomicrographs-part-5-adjusting-white-balance","status":"publish","type":"post","link":"https:\/\/wordpress.forensicpath.us\/index.php\/2024\/06\/05\/taking-and-processing-photomicrographs-part-5-adjusting-white-balance\/","title":{"rendered":"Taking and processing photomicrographs \u2014 part 5: Adjusting white balance"},"content":{"rendered":"<p>Now that you have a nice flat image after dividing by the brightfield image, you may see that the white balance is a little off.\u00a0 That division, particularly if you&#8217;ve used the division in Fiji\/ImageJ may be a little green or whatever.\u00a0 So, it&#8217;s time to make that background a bit closer to white.\u00a0 This is called fixing the &#8220;white balance.&#8221;\u00a0 <span style=\"font-size: 1rem;\">There are a number of algorithms and packages that do this.\u00a0 They all work by basically the same mechanism:<\/span><\/p>\n<ol>\n<li>Find a place in the image that should be white.<\/li>\n<li>Figure out what changes need to be done to make it white.<\/li>\n<li>Do that change to the entire image.<\/li>\n<\/ol>\n<p>There are, as you might expect, a lot of variants on this.\u00a0 Some algorithms are happy just to make white into r=g=b somewhere.\u00a0 Others try to figure out the visual stimulus values for what makes things look white.\u00a0 \u00a0And on and on.\u00a0 But basically, just like correcting for anisotropic illumination is a division, correcting white balance is (usually) a multiplication.\u00a0 The other thing that these packages differ on is finding the spot(s) to turn &#8220;really&#8221; white.\u00a0 Some take one spot and change the whole image.\u00a0 Some take a bunch of spots and change a region of the image.<\/p>\n<p>Some packages try to find the spot to use as the basis for turning things white automatically.\u00a0 Some ask the user to choose a background spot.\u00a0 I wrote a little macro in ImageJ that works pretty well.\u00a0 The algorithm is simple:<\/p>\n<ol>\n<li>Make a tiny window to place on the image<\/li>\n<li>Move the tiny window across the image, keeping track of the average rgb values<\/li>\n<li>Choose the window that had the brightest average rgb values<\/li>\n<li>Multiply the pixels by whatever it takes to make that spot 255,255,255 in integer rgb values.<\/li>\n<\/ol>\n<p>So, let&#8217;s say I move the tiny window around the image and find a place that is 180,210,200 as my brightest window average.\u00a0 I then multiply the r values of all pixels by 1.41, g by 1.21, and b by 1.27.<\/p>\n<p>There is a nice plugin macro for this by Patrice Mascalchi called ImageJ_Auto-white-balance-correction ( <a href=\"https:\/\/github.com\/pmascalchi\/ImageJ_Auto-white-balance-correction\">https:\/\/github.com\/pmascalchi\/ImageJ_Auto-white-balance-correction<\/a> ).\u00a0 In it, it has a pop up that asks you to draw a little square to be the sample that is corrected<\/p>\n<p>So, here&#8217;s an uncorrected image:<\/p>\n<p><a href=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/DSC_6223.cut_.webp\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-large wp-image-1858\" src=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/DSC_6223.cut_-1024x695.webp\" alt=\"\" width=\"688\" height=\"467\" srcset=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/DSC_6223.cut_-1024x695.webp 1024w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/DSC_6223.cut_-300x203.webp 300w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/DSC_6223.cut_-768x521.webp 768w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/DSC_6223.cut_-1536x1042.webp 1536w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/DSC_6223.cut_-1600x1085.webp 1600w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/DSC_6223.cut_.webp 2048w\" sizes=\"(max-width: 688px) 100vw, 688px\" \/><\/a><\/p>\n<p>Now I&#8217;ll run the ImageJ\/Fuji macro mageJ_Auto-white-balance-correction.\u00a0 I get this dialogue box to draw my square, which I do (in yellow):<\/p>\n<p><a href=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/Screenshot_20240605_171507.png\"><img decoding=\"async\" class=\"alignnone size-large wp-image-1860\" src=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/Screenshot_20240605_171507-1024x741.png\" alt=\"\" width=\"688\" height=\"498\" srcset=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/Screenshot_20240605_171507-1024x741.png 1024w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/Screenshot_20240605_171507-300x217.png 300w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/Screenshot_20240605_171507-768x556.png 768w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/Screenshot_20240605_171507.png 1067w\" sizes=\"(max-width: 688px) 100vw, 688px\" \/><\/a><\/p>\n<p>Here&#8217;s the result:<\/p>\n<p><a href=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/Screenshot_20240605_171415.png\"><img decoding=\"async\" class=\"alignnone size-large wp-image-1861\" src=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/Screenshot_20240605_171415-1024x690.png\" alt=\"\" width=\"688\" height=\"464\" srcset=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/Screenshot_20240605_171415-1024x690.png 1024w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/Screenshot_20240605_171415-300x202.png 300w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/Screenshot_20240605_171415-768x518.png 768w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/Screenshot_20240605_171415.png 1061w\" sizes=\"(max-width: 688px) 100vw, 688px\" \/><\/a><\/p>\n<p>Not too bad.\u00a0 You&#8217;l notice that the background isn&#8217;t flat, so the lower middle part is more red and the far right is more blue.\u00a0 That&#8217;s because I didn&#8217;t do the brightfield image division.\u00a0 This time, I&#8217;ll do that first.\u00a0 Here&#8217;s the result of doing the division using that vips library routine:<\/p>\n<p><a href=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out.jpg-scaled.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1862\" src=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out.jpg-1024x694.jpg\" alt=\"\" width=\"688\" height=\"466\" srcset=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out.jpg-1024x694.jpg 1024w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out.jpg-300x203.jpg 300w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out.jpg-768x521.jpg 768w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out.jpg-1536x1042.jpg 1536w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out.jpg-2048x1389.jpg 2048w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out.jpg-1600x1085.jpg 1600w\" sizes=\"(max-width: 688px) 100vw, 688px\" \/><\/a><\/p>\n<p>This already pretty good, and it has a flatter background, though it seems a little yellow.\u00a0 I&#8217;ll apply the ImageJ macro to this to see how it works. Hint &#8212; we are already at the point of diminishing returns:<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out.jpg.jpg-corrected-scaled.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1864\" src=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out.jpg.jpg-corrected-1024x694.jpg\" alt=\"\" width=\"688\" height=\"466\" srcset=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out.jpg.jpg-corrected-1024x694.jpg 1024w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out.jpg.jpg-corrected-300x203.jpg 300w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out.jpg.jpg-corrected-768x521.jpg 768w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out.jpg.jpg-corrected-1536x1042.jpg 1536w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out.jpg.jpg-corrected-2048x1389.jpg 2048w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out.jpg.jpg-corrected-1600x1085.jpg 1600w\" sizes=\"(max-width: 688px) 100vw, 688px\" \/><\/a><\/p>\n<p>This increased contrast a little, but more important, it&#8217;s starting to emphasize a rainbow effect in the background.<\/p>\n<p><span style=\"font-size: 1rem;\">We are running into two problems.\u00a0 The first is that the brightfield image is not perfect, so there will be small residual differences.\u00a0 The second problem is that these differences are magnified a little by doing a division that results in a very small number with small differences between pixels.\u00a0 But, when you multiply a small difference by a lot in order to restore the dynamic range, it magnifies those differences a little.\u00a0 It gets to the point that you can only polish a turd so much.\u00a0 This is where making sure you have the best original image becomes important.<\/span><\/p>\n<p>It also emphasizes the point of &#8220;good enough.&#8221;<\/p>\n<p>If you really are bothered by it, you can play one more game.<\/p>\n<ol>\n<li>Go into an image editing program (again, I use GIMP) and load the image.<\/li>\n<li>Use an automatic select tool to select the white area.\u00a0 Don&#8217;t worry about being perfect, but make sure you don&#8217;t include any of the tissue.<\/li>\n<li>Blur the bejeezus out of the white area.\u00a0 I use gaussian blur, but it doesn&#8217;t really matter. Be careful that you are not bleeding color from the tissue.<\/li>\n<li>Choose a background color from a &#8220;white&#8221; area inside the tissue part of the specimen (the area not chosen)<\/li>\n<li>Do a feathered fill of the background.<\/li>\n<li>Adjust the dynamic range to taste (I&#8217;ll talk about that in a later post)<\/li>\n<\/ol>\n<p>Here&#8217;s the result.\u00a0 Note that this is for aesthetics.\u00a0 We have left any idea of measuring color or anything like that behind.\u00a0 I&#8217;ll talk about using this stuff for publication in a later post.<\/p>\n<p><a href=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out-1.jpg-1.jpg-corrected-1-scaled.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1866\" src=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out-1.jpg-1.jpg-corrected-1-1024x694.jpg\" alt=\"\" width=\"688\" height=\"466\" srcset=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out-1.jpg-1.jpg-corrected-1-1024x694.jpg 1024w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out-1.jpg-1.jpg-corrected-1-300x203.jpg 300w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out-1.jpg-1.jpg-corrected-1-768x521.jpg 768w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out-1.jpg-1.jpg-corrected-1-1536x1042.jpg 1536w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out-1.jpg-1.jpg-corrected-1-2048x1389.jpg 2048w, https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/out-1.jpg-1.jpg-corrected-1-1600x1085.jpg 1600w\" sizes=\"(max-width: 688px) 100vw, 688px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>There is a tool in GIMP to adjust the white balance either visually or automatically.\u00a0 I don&#8217;t like either one much.<\/p>\n<p>So, here&#8217;s the final result compared to the original image:<\/p>\n<p><a href=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/Untitled-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-1867\" src=\"https:\/\/wordpress.forensicpath.us\/wp-content\/uploads\/2024\/06\/Untitled-1-1024x349.jpg\" alt=\"\" width=\"1022\" height=\"352\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now that you have a nice flat image after dividing by the brightfield image, you may see that the white&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[99,60],"tags":[27,25,26],"class_list":["post-1856","post","type-post","status-publish","format-standard","hentry","category-forensic-pathology","category-photomicrographs","tag-image-processing","tag-microscopy","tag-photomicrography"],"_links":{"self":[{"href":"https:\/\/wordpress.forensicpath.us\/index.php\/wp-json\/wp\/v2\/posts\/1856","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.forensicpath.us\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.forensicpath.us\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.forensicpath.us\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.forensicpath.us\/index.php\/wp-json\/wp\/v2\/comments?post=1856"}],"version-history":[{"count":1,"href":"https:\/\/wordpress.forensicpath.us\/index.php\/wp-json\/wp\/v2\/posts\/1856\/revisions"}],"predecessor-version":[{"id":1868,"href":"https:\/\/wordpress.forensicpath.us\/index.php\/wp-json\/wp\/v2\/posts\/1856\/revisions\/1868"}],"wp:attachment":[{"href":"https:\/\/wordpress.forensicpath.us\/index.php\/wp-json\/wp\/v2\/media?parent=1856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.forensicpath.us\/index.php\/wp-json\/wp\/v2\/categories?post=1856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.forensicpath.us\/index.php\/wp-json\/wp\/v2\/tags?post=1856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}