Alp’s Label Crop Tool

Updated!

Hello,

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.

 

Download: Alp’s Label Crop Tool (01may2017, Windows)

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.

Alper

 

Downloads

Alp’s Label Crop Tool (01may2017, Windows)

  • 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).

Alp’s Label Crop Tool (29apr2017, Windows)

  • Information available in the main text, above.

Alp’s Label Crop Tool (20mar2017, Windows & Ubuntu)

  • 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.

9 thoughts on “Alp’s Label Crop Tool

  1. Hello , thanks for your plugins , i find it really helpful for my uses , i would like to know if this crop tool is available for ubuntu ?

    Like

    1. Hello, I’m glad the plugins worked for you. I just checked and Label Crop Tool_Windows works well in Ubuntu too (14.04), I added relevant info to the page.

      Liked by 1 person

  2. Hi..Thanks for this article. I kind of got lost after downloading “Alp’s Label Crop Tool (01may2017, Windows)”. I already have a folder called plugins in my fiji directory. Where do I put this ALP plugins directory ?

    In my downloaded “ALT_Windows_22mar2017” folder I have another plugins directory which further has an ActionBar folder and a “Alps_Labeling_Tool.ijm” file.

    Please note that I have already installed ActionBar plugin through fifi->plugins->inatall.

    Thanks

    Like

    1. Hi, installation is pretty straightforward, the newer versions always overwrites the older versions and folder structure is always the same.
      You should have only one plugins folder in Fiji directory. and in the Plugins folder, there must be only one Actionbar folder. If you think folder structure is messed up, just extract original fiji app to another location and reinstall everything to there, then if everything is ok, you may delete the old fiji.app folder, if you are not using some other custom plugins.

      Like

  3. Hello,
    I am trying to use your AIMS tool for segmentation. AIMS allows me to create 100 roi (same class) and when I try to “save the labels and image”, it gives “unable to make band” error at the very last stage. It generate masked/labled image with colored roi and the roi name, but not saving the masked file without the roi names.

    Any suggestion would be very helpful.

    Nishant

    Like

      1. Thanks for your prompt reply, I am sorry that I was not clear.
        Yes, they are all on the same image. I have 100 objects on single image and I want to create label image for instance segmentation where I will have 100 objects and background. I hope it helps.

        Thanks again
        Nishant

        Like

Leave a reply to Nishant Cancel reply