This topic is a linked part of a larger work: “Open source optical coffee sorter project”.
Content
- 4.1. Renaming
- 4.2. Install GIMP
- 4.3. Set up the export_paths_to_png.py script
- 4.4. Set up the set_paths_visibility.py script
- 4.5. Configure keyboard shortcuts in GIMP to speed up this process.
- 4.6. Create “paths” for individual coffee beans in an image.
- 4.7. Use the export_paths_to_png.py script on an image of coffee beans to create 220×220 px images in PNG format of individual beans.
- 4.8. Repeat the last two steps for all images of coffee beans for which the process has not yet been done
1. Introduction
This document shows our process for adding images to our open source coffee beans dataset, which we use to train the decision algorithms of our optical coffee sorter.
Everyone can create and contribute images, and all contributions are valuable because coffee beans differ wildly by variety and cultivation conditions. A smartphone with camera is enough to contribute. The image capture mode of our optical coffee sorter is more efficient (but the sorter is not yet finished, and not every contributor will have one).
2. Capturing the images
3. Enhancing the images
-
If you have pictures that are overexposed: use “Colors → Levels” and for channel “Value” map the visible part of the histogram (in logarithmic display mode) to target values “0 … 245”. For the source values, you can set the white point so it includes all white tones with high histogram values, mapping the even whiter ones (that occur rarely) to pure white this way.
-
If you have pictures that have a lot of stray light (“whitewashed low contrast appearance”): same as before, but map to 0 … 255 since they do not have to appear visually darker overall.
-
If you have pictures that have the wrong light temperature setting: open the “Colors → Levels” dialog and use the “grey point” button to select a point on the white background. This will adjust the channel gamma values for each color channel differently so that the color of the selected pixel appears neutral gray.
-
Alternative if the pictures are overexposed: use the “Colors → Auto → Normalize” filter. If necessary use “Brightness -30, Contrast +10” after that.
-
If the pictures are underexposed: set “Brightness +70, Contrast +20”. But often, pictures cannot be properly rescued in such cases.
4. Splitting the images
The Photo that you take of coffee beans is obviously collection of it; since that’s not efficient and smart. So you take photo for collection of bad and good beans separately. Once you have finished taking photo, you might want to separate each of the beans from those photo.
Following is the Steps/Procedures for splitting coffee beans:
4.1. Renaming:
- Keep all good and bad images in separate folder. Example: Set01-good and Set01-bad
- Rename each images. Example: Set01-good.01, Set01-bad.01, and soon.
4.2. Install GIMP
4.3. Set up the export_paths_to_png.py script
- Download this file
- Paste downloaded file in “C:\Program Files\GIMP 2\lib\gimp\2.0\plug-ins”
4.4. Set up the set_paths_visibility.py script
- Download this file
- Paste to the same location as you did in previous step.
4.5. Configure keyboard shortcuts in GIMP to speed up this process
- Open GIMP Edit → Preferences → Interface
- Keyboard shortcut section → Configure Keyboard shortcut
- Search for Selection to path and Set paths visibility
- Click once on disable of Selection to path not Selection to path(advance) and assign E → Reassign Shortcut
- Do same for Set paths visibility and assign Ctrl + A → Click Close → Ok
4.6. Create “paths” for individual coffee beans in an image
- Use the rectangular selection tool and set its tool options to Fixed: Size
- Create a selection with one bean in its center.
- Press E to create a new path.
- Occasionally press Ctrl + A to show the “Set paths visibility” dialog and use it to show all paths. So you can see which beans you did not yet “process”.
- Select one path in the Paths dialog, press Return, rename it to a two-digit number (01, 02, 03 etc.), press Return to confirm and an arrow to select the next one. This is the fastest way to work through the whole list to rename all.
4.7. Use the export_paths_to_png.py script on an image of coffee beans to create 220×220 px images in PNG format of individual beans
- Select Filter → Paths → Export paths to PNG".
- In the dialog, always select the same output folder for the PNG export images of all source images.
- In the dialog, select Export Paths: All paths.
- In the dialog, set a prefix Set01-good.01. (or whatever is the part of your source image filename before the .png).
- Click “OK”. The result will be files Set01-good.01.01.png, Set01-good.01.02.png etc., for all your paths.
- Also save the full image in GIMP’s .xcf.bz2 format, by choosing File → Save as … in GIMP. Example : Set01.good.01.xcf.bz2 for image Set01.good.01.jpg