Hello together,
I'm looking for way to threshold an image and in the same process making it binary. Process > Binary > Make Binary sometimes caused plausible black/white dominance switches. Process > Math > Macro works better for my purposes (i.e.| if (v<=25) v=0; else v=255) The later Expression is very slow compared even to an Gaussian Blur or similar. Are there other, hopefully faster ways (for high resolution) to threshold and make binary (8bit)? I tried .. setMinAndMax(173, 173); .. but this does no clamping like I thought it might.. Any help is much appreciated. Best regards, Rainer -- Rainer M. Engel, Dipl. Digital Artist scientific|Media GbR Pichelsdorfer Str. 143 13595 Berlin -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Rainer,
Check out the ByteProcessor::threshold function: Sets pixels less than or equal to level to 0 and all other pixels to 255. HTH and best regards, John Le 22 mai 2014 à 11:23, Rainer M. Engel a écrit : > Hello together, > > I'm looking for way to threshold an image and in the same process making > it binary. > > Process > Binary > Make Binary > sometimes caused plausible black/white dominance switches. > > Process > Math > Macro > works better for my purposes (i.e.| if (v<=25) v=0; else v=255) > > The later Expression is very slow compared even to an Gaussian Blur or > similar. Are there other, hopefully faster ways (for high resolution) to > threshold and make binary (8bit)? > > I tried .. > setMinAndMax(173, 173); > .. but this does no clamping like I thought it might.. > > Any help is much appreciated. > > Best regards, > Rainer > > > -- > Rainer M. Engel, Dipl. Digital Artist > scientific|Media GbR > Pichelsdorfer Str. 143 > 13595 Berlin > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hello John,
that is definitely worth a look. Maybe also the already available "Image Expression Parser"?, although then I would like to know how does the Macro Expression work? Isn't it build upon the ByteProcessor function and hence it won't get faster? Rainer Am 22.05.2014 12:08, schrieb John Hayes: > Hi Rainer, > > Check out the ByteProcessor::threshold function: > Sets pixels less than or equal to level to 0 and all other pixels to 255. > > HTH and best regards, > > John > > Le 22 mai 2014 à 11:23, Rainer M. Engel a écrit : > >> Hello together, >> >> I'm looking for way to threshold an image and in the same process making >> it binary. >> >> Process > Binary > Make Binary >> sometimes caused plausible black/white dominance switches. >> >> Process > Math > Macro >> works better for my purposes (i.e.| if (v<=25) v=0; else v=255) >> >> The later Expression is very slow compared even to an Gaussian Blur or >> similar. Are there other, hopefully faster ways (for high resolution) to >> threshold and make binary (8bit)? >> >> I tried .. >> setMinAndMax(173, 173); >> .. but this does no clamping like I thought it might.. >> >> Any help is much appreciated. >> >> Best regards, >> Rainer >> >> >> -- >> Rainer M. Engel, Dipl. Digital Artist >> scientific|Media GbR >> Pichelsdorfer Str. 143 >> 13595 Berlin >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Rainer,
On 23.05.2014, 12:15 PM, Rainer M. Engel wrote: > Am 22.05.2014 12:08, schrieb John Hayes: >> Check out the ByteProcessor::threshold function: >> Sets pixels less than or equal to level to 0 and all other pixels to 255. You should not need to dive into low-level API programming to perform thresholding and binarization. >> Le 22 mai 2014 à 11:23, Rainer M. Engel a écrit : >> >>> I'm looking for way to threshold an image and in the same process making >>> it binary. The macro recorder (Plugins > Macros > Record...) records the following when clicking "Apply" in the threshold window: setAutoThreshold("Default dark"); setOption("BlackBackground", true); run("Convert to Mask"); >>> >>> Process > Binary > Make Binary >>> sometimes caused plausible black/white dominance switches. I guess you mean inconsisten results dependent on whether "Black background" is activated in Process > Binary > Options... (see http://imagej.nih.gov/ij/docs/guide/146-29.html#infobox:blackBackground for documentation) setOption("BlackBackground", true); >>> >>> Process > Math > Macro >>> works better for my purposes (i.e.| if (v<=25) v=0; else v=255) >>> >>> The later Expression is very slow compared even to an Gaussian Blur or >>> similar. Are there other, hopefully faster ways (for high resolution) to >>> threshold and make binary (8bit)? >>> >>> I tried .. >>> setMinAndMax(173, 173); >>> .. but this does no clamping like I thought it might.. You probably want to use something like setThreshold(0, 173); to set the Threshold to a specified value. Hope that helps, Jan -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Rainer M. Engel
Hi Rainer,
> Process > Binary > Make Binary > sometimes caused plausible black/white dominance switches. If you have this problem, it is most likely caused by different settings of 'Black Background' in Process>Binary>Options. You should also check whether the image has an inverted LUT. > I tried .. > setMinAndMax(173, 173); > .. but this does no clamping like I thought it might.. The setMinAndMax changes only the display, not the image data. For 8-bit images, this is done via the LUT, so you can apply the LUT afterwards, and the image will be converted to 0 (values less or equal 173) and 255 (values higher than 173). The mapping will be independent on LUT and Black background settings: setMinAndMax(173, 173); run("Apply LUT"); Michael ________________________________________________________________ On May 22, 2014, at 11:23, Rainer M. Engel wrote: > Hello together, > > I'm looking for way to threshold an image and in the same process making > it binary. > > Process > Binary > Make Binary > sometimes caused plausible black/white dominance switches. > > Process > Math > Macro > works better for my purposes (i.e.| if (v<=25) v=0; else v=255) > > The later Expression is very slow compared even to an Gaussian Blur or > similar. Are there other, hopefully faster ways (for high resolution) to > threshold and make binary (8bit)? > > I tried .. > setMinAndMax(173, 173); > .. but this does no clamping like I thought it might.. > > Any help is much appreciated. > > Best regards, > Rainer -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thank you Michael and Jan,
good advice which will work in most cases. Very good. Then, what would be the best (fastest) method to filter for a distinct color value. The Macro Expression did not seem to be very fast on that. Someting like "Replace value" (Plugin, FIJI) for 32bit images would be great, although I did not test it for speed so far. Speed: run("Macro...", "code=[if (v==127) v=0;]"); -> 12547ms run("Replace value", "pattern=127 replacement=0"); -> 125ms But the plugin does not care about ROIs ... I'm not sure if I can modify the plugins code, anyway, maybe I'll have a look some time. Should be feasible ;-) Best regards, Rainer Am 23.05.2014 14:59, schrieb Michael Schmid: > Hi Rainer, > >> Process > Binary > Make Binary >> sometimes caused plausible black/white dominance switches. > > If you have this problem, it is most likely caused by different settings of 'Black Background' in Process>Binary>Options. You should also check whether the image has an inverted LUT. > >> I tried .. >> setMinAndMax(173, 173); >> .. but this does no clamping like I thought it might.. > > The setMinAndMax changes only the display, not the image data. For 8-bit images, this is done via the LUT, so you can apply the LUT afterwards, and the image will be converted to 0 (values less or equal 173) and 255 (values higher than 173). The mapping will be independent on LUT and Black background settings: > > setMinAndMax(173, 173); > run("Apply LUT"); > > > Michael > ________________________________________________________________ > On May 22, 2014, at 11:23, Rainer M. Engel wrote: > >> Hello together, >> >> I'm looking for way to threshold an image and in the same process making >> it binary. >> >> Process > Binary > Make Binary >> sometimes caused plausible black/white dominance switches. >> >> Process > Math > Macro >> works better for my purposes (i.e.| if (v<=25) v=0; else v=255) >> >> The later Expression is very slow compared even to an Gaussian Blur or >> similar. Are there other, hopefully faster ways (for high resolution) to >> threshold and make binary (8bit)? >> >> I tried .. >> setMinAndMax(173, 173); >> .. but this does no clamping like I thought it might.. >> >> Any help is much appreciated. >> >> Best regards, >> Rainer > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Rainer,
oops, there is one more macro function that I overlooked, probably the method of choice: changeValues(v1, v2, v3) Changes pixels in the image or selection that have a value in the range v1-v2 to v3. For example, changeValues(0,5,5) changes all pixels less than 5 to 5. It honors the ROI. http://imagej.nih.gov/ij/developer/macro/functions.html#changeValues The reason why run("Macro...", "code=[if (v==127) v=0;]"); is slower than Java code: The code is executed not in Java but in the ImageJ macro interpreter. For each pixel, it reads you macro code again and then decides what to do, based on that code. Of course, this takes additional time, even though the ImageJ macro interpreter is programmed very efficiently. Michael ________________________________________________________________ On May 23, 2014, at 16:03, Rainer M. Engel wrote: > Thank you Michael and Jan, > > good advice which will work in most cases. Very good. > > Then, what would be the best (fastest) method to filter for a distinct > color value. The Macro Expression did not seem to be very fast on that. > > Someting like "Replace value" (Plugin, FIJI) for 32bit images would be > great, although I did not test it for speed so far. > > Speed: > run("Macro...", "code=[if (v==127) v=0;]"); -> 12547ms > run("Replace value", "pattern=127 replacement=0"); -> 125ms > > But the plugin does not care about ROIs ... > > I'm not sure if I can modify the plugins code, anyway, maybe I'll have a > look some time. Should be feasible ;-) > > Best regards, > Rainer > > > Am 23.05.2014 14:59, schrieb Michael Schmid: >> Hi Rainer, >> >>> Process > Binary > Make Binary >>> sometimes caused plausible black/white dominance switches. >> >> If you have this problem, it is most likely caused by different settings of 'Black Background' in Process>Binary>Options. You should also check whether the image has an inverted LUT. >> >>> I tried .. >>> setMinAndMax(173, 173); >>> .. but this does no clamping like I thought it might.. >> >> The setMinAndMax changes only the display, not the image data. For 8-bit images, this is done via the LUT, so you can apply the LUT afterwards, and the image will be converted to 0 (values less or equal 173) and 255 (values higher than 173). The mapping will be independent on LUT and Black background settings: >> >> setMinAndMax(173, 173); >> run("Apply LUT"); >> >> >> Michael >> ________________________________________________________________ >> On May 22, 2014, at 11:23, Rainer M. Engel wrote: >> >>> Hello together, >>> >>> I'm looking for way to threshold an image and in the same process making >>> it binary. >>> >>> Process > Binary > Make Binary >>> sometimes caused plausible black/white dominance switches. >>> >>> Process > Math > Macro >>> works better for my purposes (i.e.| if (v<=25) v=0; else v=255) >>> >>> The later Expression is very slow compared even to an Gaussian Blur or >>> similar. Are there other, hopefully faster ways (for high resolution) to >>> threshold and make binary (8bit)? >>> >>> I tried .. >>> setMinAndMax(173, 173); >>> .. but this does no clamping like I thought it might.. >>> >>> Any help is much appreciated. >>> >>> Best regards, >>> Rainer >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> >> > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
> It honors the ROI.
I honor and appreciate your engagement and the work everyone has put into this piece of software.. Thank you for your time and tips! A nice weekend to everyone out there.. Rainer Am 23.05.2014 16:18, schrieb Michael Schmid: > Hi Rainer, > > oops, there is one more macro function that I overlooked, probably the method of choice: > > changeValues(v1, v2, v3) > > Changes pixels in the image or selection that have a value in the range v1-v2 to v3. For example, changeValues(0,5,5) changes all pixels less than 5 to 5. > It honors the ROI. > > http://imagej.nih.gov/ij/developer/macro/functions.html#changeValues > > The reason why > run("Macro...", "code=[if (v==127) v=0;]"); > is slower than Java code: The code is executed not in Java but in the ImageJ macro interpreter. For each pixel, it reads you macro code again and then decides what to do, based on that code. Of course, this takes additional time, even though the ImageJ macro interpreter is programmed very efficiently. > > Michael > ________________________________________________________________ > On May 23, 2014, at 16:03, Rainer M. Engel wrote: > >> Thank you Michael and Jan, >> >> good advice which will work in most cases. Very good. >> >> Then, what would be the best (fastest) method to filter for a distinct >> color value. The Macro Expression did not seem to be very fast on that. >> >> Someting like "Replace value" (Plugin, FIJI) for 32bit images would be >> great, although I did not test it for speed so far. >> >> Speed: >> run("Macro...", "code=[if (v==127) v=0;]"); -> 12547ms >> run("Replace value", "pattern=127 replacement=0"); -> 125ms >> >> But the plugin does not care about ROIs ... >> >> I'm not sure if I can modify the plugins code, anyway, maybe I'll have a >> look some time. Should be feasible ;-) >> >> Best regards, >> Rainer >> >> >> Am 23.05.2014 14:59, schrieb Michael Schmid: >>> Hi Rainer, >>> >>>> Process > Binary > Make Binary >>>> sometimes caused plausible black/white dominance switches. >>> >>> If you have this problem, it is most likely caused by different settings of 'Black Background' in Process>Binary>Options. You should also check whether the image has an inverted LUT. >>> >>>> I tried .. >>>> setMinAndMax(173, 173); >>>> .. but this does no clamping like I thought it might.. >>> >>> The setMinAndMax changes only the display, not the image data. For 8-bit images, this is done via the LUT, so you can apply the LUT afterwards, and the image will be converted to 0 (values less or equal 173) and 255 (values higher than 173). The mapping will be independent on LUT and Black background settings: >>> >>> setMinAndMax(173, 173); >>> run("Apply LUT"); >>> >>> >>> Michael >>> ________________________________________________________________ >>> On May 22, 2014, at 11:23, Rainer M. Engel wrote: >>> >>>> Hello together, >>>> >>>> I'm looking for way to threshold an image and in the same process making >>>> it binary. >>>> >>>> Process > Binary > Make Binary >>>> sometimes caused plausible black/white dominance switches. >>>> >>>> Process > Math > Macro >>>> works better for my purposes (i.e.| if (v<=25) v=0; else v=255) >>>> >>>> The later Expression is very slow compared even to an Gaussian Blur or >>>> similar. Are there other, hopefully faster ways (for high resolution) to >>>> threshold and make binary (8bit)? >>>> >>>> I tried .. >>>> setMinAndMax(173, 173); >>>> .. but this does no clamping like I thought it might.. >>>> >>>> Any help is much appreciated. >>>> >>>> Best regards, >>>> Rainer >>> >>> -- >>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >>> >>> >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- ################################### Rainer M. Engel - Managing Director endime | ENGEL DIGITAL MEDIA Pichelsdorfer Str. 143 13595 Berlin Ust-StNr.:DE254256305 BLZ: 20010020 Kto: 971873201 web: www.endime.de mail: [hidden email] fon.:-Berlin +49 (0)30-92252096 mobile: +49 (0)174 33 555 49 skype: tomdooley4711 ################################### not only a game http://cx.endime.de ################################### -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |