The script / macro I send is just the result of the color threshold plugin.
Please follow the workflow 1 to 5 and adjust the settings for the color threshold base on your needs.
The color threshold need to be record in a macro
see the recorder function and the macro.
28.2.5 Color Threshold…
Thresholds 24-bit RGB images based on Hue Saturation and Brightness (HSB), Red Green and Blue (RGB), CIE Lab or YUV components. Ranges of the filters can be set manually or based on the pixel value components of a user-defined ROI. This command, implemented in version 1.43l, is an experimental built-in version of the Threshold Colour plugin  and is not yet fully integrated into ImageJ.
Figure 21 Segmentation of DAPI stained nuclei using Image▷Adjust▷Color Threshold…↑
Pass If checked, values within range are thresholded and displayed (band-pass filter), otherwise, values outside the selected range are thresholded (band-reject filter).
Thresholding Method Allows any of the 16 different automatic thresholding methods to be selected ( see Threshold… [T]↑).
Threshold Color Selects the threshold color: either Red , Black , White or Black & White ( see Threshold… [T]↑).
Color space Selects the color space: HSB , RGB , CIE Lab or YUV ( see Color Spaces and Color Separation↑).
Dark background To be checked when features are lighter than the background ( see 23: Interpreting Binary Images↓). The state of the checkbox is remembered across restarts.
Original Restores the original image and updates the buffer when switching to another image.
Filtered Shows the filtered image. Note that the final thresholded image type is RGB, not 8-bit gray ( see Image Types and Formats↑).
Select Creates a ROI selection based on the current settings. The selection is made according to the settings defined in the Process▷Binary▷Options…↓ dialog.
Sample (Experimental) Sets the ranges of the filters based on the pixel value components in a user-defined ROI.
Stack Processes the remaining slices of the stack (if any) using the current settings.
Macro Creates a macro based on the current settings which is sent to the Macro Recorder window (Plugins▷Macros▷Record…↓), if open.
Help Opens the built-in help dialog.