Sometimes, you may want to try images at various resolutions with the same deep learning model, to overcome issues related to resolution (model’s needs, memory problems, etc.). Or, you may need to crop a part of your image which changes resolution but preserves original scale. Or, you may have very large image files (scanned images etc) like me and looking for largest possible image size that fits to current video RAM available. Of course Its not an easy job to re-establish all your labels, after such resolution modifications.
I am tired of doing “re-labeling” several times and decided to create labels on orginal, hi-res scanned image (in my case, image size is like 10k x 30k). Now with help of this tool, I can make several (custom sized) crops from main image, it crops and saves the selected rectangle part of image, along with annotations contained in selection. Current version reads and saves Detectnet formatted annotations only. If you need, later you can convert them to Yolo format, with Yolo converter.
Installation & Usage
To install this Fiji plugin, click the download link below to download the archive file, open archive, drag and drop “plugins” directory found in archive onto your Fiji folder (please see my labeling tool page for Fiji installation, required for label crop plugin). Current version is tested under Windows 10.
For 29apr2017 version, you will need an updated “action bar” plugin available here.
Some manual steps are required if you formerly installed action bar plugin 2.02 version. Please open Fiji.app folder, then plugins folder. Find “action_bar202.jar” file and delete it. Paste the new action bar plugin to the same directory. Open Fiji and and then close. Its ready.
If you are installing for the first time, after installing Fiji, download the new action bar plugin and save it to your “/Fiji.app/plugins/” folder. Run Fiji. From main menu, select “Plugins/Install plugin”, and choose “action_bar-2.0.5-SNAPSHOT.jar” file in plugins folder, choose OK for warnings and restart Fiji. Action Bar plugin is now installed.
Now you can see plugin’s name in “Plugins” main menu in Fiji. After choosing it, a sticky side menu will appear.
Open Image: Choose the high resolution image with annotations. Just be sure the annotation .txt file exist and located in the same directory with the image. After opening image, a dialog window will ask you the crop size you are planning to apply. Enter rectangle selection size (in pixels). The selection box at provided size will appear at topleft corner of main image. You can freely move it with mouse to anywhere, to the area you want to crop as a new image.
Make Selection: Use this button to create and set width and height of selection rectangle, in case it disappears or you want to change box dimensions.
Set CropNo&Folder: This button opens a dialog box.
In first entry, you are setting the starting number of four-digit prefix, for the filename of crops you are going to save, i.e, if you set 12, your crop-saved filenames will start as “0012_”
Second entry is the folder you will save cropped images and their labels.
Save Current Box: Use this button to save the selected image area and the annotations that falls within selection, into the folder you set, above. Your saves will be prefix-numbered starting from the number you set above. After saving selection, you can move the rectangle, and click “Save Cropping” again. The new area will be saved with increased prefix number.
This way, you can just move the selection rectangle to new position and hit “Save Current Box” without worrying about filename issues.
Process Whole Image: This button uses a sliding window and saves crops to disk, along with annotations that fall into cropped area (only the labels thats fully fall into crop area). Use “Set CropNo&Folder” button if you want to start from a certain number, or from 1, and want to save cropped parts into a different folder. Use offset values if you want crops shift into the former crop (both x and y offsets possible.
In case you encounter a problem with menu visibility, I advise quitting Fiji and re-run (alternatively, you can manually open any image, sticky menu re-appears and sticks to it).
Please keep in mind that the Label Crop plugin is arranged to include only the annotations fully contained in selection rectangle. Therefore partially covered annotation boxes in the selection rectangle in main image will not be processed.
This software is provided “as is”. Please use at your own risk. I hope it helps to you too.
- A new button added, “Process Whole Image“. Asks 4 parameters, width and height of the sliding crop box, and slide offsets, as X and Y pixels (If you dont want to use any offsets, please enter 0).
- Information available in the main text, above.
- Open Image: Choose the high resolution image with annotations. Just be sure the annotation .txt file exist and located in the same directory with the image. After opening image, a dialog window will ask you the crop size you are planning to apply. Enter rectangle selection size (in pixels). The selection box at provided size will appear at topleft corner of main image. You can freely move it with mouse to anywhere, to the area you want to crop as a new image.
- Apply Crop: After moving selection box, hit Apply Crop button to create a cropped copy of that area.
- Save Cropping: Use this button to save the cropped image. It will ask you where you want to save it and with which image format (jpeg, png…). Upon completion, a new image file with a name you provided will be saved along with a text file containing annotations in Detectnet format.