Welcome to the forums!
This is definitely a good task to begin on. Use the links below to educate yourself a little bit on ImageJ macro programming and I’m sure you can tackle this problem with ease. It also requires knowing what to do to process the images as well, but you have a really good example here.
Introduction to Macro Programming in ImageJ - You can use the macro recorder (Plugins > Macros > Record…) to find out how to code the actions that you are doing in ImageJ, then you can write a simple script.
Built-in Macro Functions - All of the pieces of code for other useful functions in ImageJ that you might not be able to find from the macro recorder.
With regards to your problem, as the rectangular border and particles are very well contrasted to the rest of the image, we can ‘threshold’ the image to leave us with just the black objects. To do this, I converted the image to 8-bit (from RGB; Image > Type > 8-bit). Then, I used the default threshold (Image > Adjust > Threshold…) to make the image black and white (binary) where the objects are black on a white background.
Next, we can use this binary image to obtain the rectangular border. Using the analyze particles plugin (Analyze > Analyze Particles…) with default settings (see below) we can obtain all of the objects as discrete selections, which are sent to the ROI manager.
The rectangular border is one giant selection, much larger than the rest. This can be identified in a macro, and maybe I’ll leave you to figure out how you might code this. Once the rectangular border ROI is identified, we can select it and clear the outside of the border from the image to remove unwanted particles from detection (Edit > Clear Outside).
Now we are left with just the particles inside or on the border, using the analyze particles plugin again we can obtain all of the particles as ROIs and measure their shape/area or just count them.
Some things to note:
- The particles on the border will not be counted this way
- Your images do not look uniformly lit, so you may find that the threshold sometimes doesn’t work as intended. This can be tweaked to best fit all images, but may need adjusting for multiple different images.
- You have some objects that are very close, this would require some advanced segmentation to separate them - you should research watershed segmentation
Automation by scripting this process should be very easy, have a go using the macro recorder and the links provided and come back to us with any problems.