Skip to content

Jython script for ImageJ/FIJI to automatically crop images/stacks to remove black edges.

License

Notifications You must be signed in to change notification settings

agclark12/autocrop_black_edges

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Autocrop_Black_Edges.py

This is a jython script for ImageJ/FIJI that automatically crops images that have black edges around the outsides. Such black edges commonly appear after registering image stacks.

Installation

To install this script to ImageJ or FIJI, just drop it into the plugins folder. For OSX users, right click on the ImageJ or FIJI icon in the finder and click "Show Package Contents" to find the plugins folder. Then restart ImageJ/FIJI and you should see "Autocrop Black Edges" at the bottom of the Plugins menu.

Alternatively, you can drag the .py file into ImageJ/FIJI and it will open it in the editor. Then you can just run it from there.

Using the plugin

The plugin will work on the active image. If there are no images open, you will get an error message to that effect. The cropped image will be labeled with "_autocrop" at the end of the filename. You can test the plugin using the example image stack provided here.

It may be useful to use this plugin in batch. You can incorporate it into an ImageJ macro by calling run("Autocrop Black Edges");. For example, if you want to autocrop all of the .tif files in a directory:

setBatchMode(true);
dir = getDirectory("Which directory?");
dir_list = getFileList(dir);
extension = ".tif";

for (i=0;i<lengthOf(dir_list);i++) {
    if (endsWith(dir_list[i],extension)) {
        open(dir + dir_list[i]);
        title = getTitle();
        title_new = replace(title, extension, "_autocrop" + extension);
        run("Autocrop Black Edges");
        selectWindow(title_new); //you only need this for batch mode
        saveAs(dir + title_new);
        run("Close All");
    }
}

Please let me know if you have any trouble using this or if it is giving any unexpected results. Thanks!

About

Jython script for ImageJ/FIJI to automatically crop images/stacks to remove black edges.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages