A MATLAB App Designer GUI created to accelerate the process of building an image dataset for machine learning. This app allows a user to load a video file, navigate through its frames, and interactively crop specific objects (e.g., crystals) to save them as individual image files.
Training a computer vision model requires a large, well-labeled dataset. Manually creating this dataset by capturing, separating, and cropping images is tedious and time-consuming. This application streamlines the workflow by leveraging video recordings. A user can record a video of multiple crystals, and then use this tool to quickly extract high-quality, tightly-cropped images of each one, making dataset creation significantly faster.
- Load Video: Supports common video formats (
.mp4,.avi,.mov). - Frame Navigation: Navigate through video frames using a slider for quick seeking or next/previous buttons for precise, frame-by-frame control.
- Interactive Cropping: Interactively draw a rectangle on the video frame to select the exact region of interest. The app is robust against misclicks on other UI elements during the cropping process.
- Custom Output Folder: Choose and set any destination folder for the saved image files.
- Session Counter: Keep track of how many images have been cropped and saved during the current session.
To run this application, you will need:
- MATLAB (Recommended: R2020a or newer)
- Image Processing Toolbox™ (This is essential for video reading and
imcropfunctionality)
- Clone or download this repository to your local machine.
- Open MATLAB and navigate to the project's root folder.
- Open the
.mlappfile (e.g.,CrystalCropperGUI.mlapp). This will launch the MATLAB App Designer. - Click the Run button in the App Designer's toolbar.
- Set Output Folder: Click the "Set Output Folder" button to choose where your cropped images will be saved. It defaults to a
Cropped_Crystalsfolder in the project directory. - Load Video: Click the "Load Video" button and select your video file. The first frame will appear.
- Navigate: Use the slider or the "Next" / "Previous" buttons to find a frame with a clear view of a crystal. Use the built-in axes zoom tools if needed.
- Crop Crystal: Click the "Crop Crystal" button. Your cursor will change to a crosshair. Click and drag a box around the crystal.
- Confirm Crop: Once the rectangle is drawn, click the "Confirm Crop" button. The selected area will be saved as a
.pngfile with a unique, timestamped name in your chosen output folder. The on-screen counter will update. - Repeat steps 7-9 to continue building your dataset.
The application interface is composed of the following main components:
| Component | Functionality |
|---|---|
| Set Output Folder Button | Opens a dialog to select the destination folder for saved images. |
| Output Folder Field | A read-only field that displays the current save path. |
| Load Video Button | Opens a file dialog to select a video. Resets the session counter. |
| Main Display (UIAxes) | Displays the current video frame where all interactions take place. |
| Frame Slider | Allows for quick seeking through the video's frames. |
| Previous/Next Buttons | Provide precise, single-frame navigation. |
| Crop Crystal Button | Activates the drawing mode to let you select a rectangular region. |
| Confirm Crop Button | Confirms the selection, performs the crop, saves the image, and updates the counter. |
| Crystals Saved Label | Displays the number of images saved in the current session. |
This repository includes a .gitignore file. This file is configured to intentionally ignore the default Cropped_Crystals/ folder. This prevents the large number of generated image files from being accidentally committed to the Git repository. If you use a custom output folder, it is recommended that you add its name to the .gitignore file as well.
