@@ -0,0 +1,2575 @@
+%22%22%22Script to calculate cell areas from a curated image of cell outlines.%0A%0AOutputs csv file with cell areas as well as an image where the colour%0Aof each cell represents its area.%0A%22%22%22%0A%0Aimport os%0Aimport logging%0Aimport argparse%0A%0Afrom jicbioimage.core.image import Image%0Afrom jicbioimage.core.io import AutoName, AutoWrite%0A%0Afrom utils import (%0A    identity,%0A    invert,%0A    logical_and,%0A    erode_binary,%0A    connected_components,%0A    watershed_with_seeds,%0A)%0A%0A__version__ = %220.3.0%22%0A%0AAutoName.prefix_format = %22%7B:03d%7D_%22%0A%0A%0Adef analyse_file(image_fpath, mask_fpath, output_directory):%0A    %22%22%22Analyse a single file.%22%22%22%0A    logging.info(%22Analysing file: %7B%7D%22.format(image_fpath))%0A    image = Image.from_file(image_fpath)%0A%0A    logging.info(%22Mask file: %7B%7D%22.format(mask_fpath))%0A    mask = Image.from_file(mask_fpath)%5B:, :, 0%5D%0A    mask = identity(mask)%0A%0A    seeds = invert(image)%0A    seeds = erode_binary(seeds.view(bool))%0A    seeds = logical_and(seeds, mask)%0A    seeds = connected_components(seeds, connectivity=1)%0A    segmentation = watershed_with_seeds(-image, seeds, mask)%0A%0A%0Adef main():%0A    # Parse the command line arguments.%0A    parser = argparse.ArgumentParser(description=__doc__)%0A    parser.add_argument(%22input_file%22, help=%22Input file%22)%0A    parser.add_argument(%22mask_file%22, help=%22Mask file%22)%0A    parser.add_argument(%22output_dir%22, help=%22Output directory%22)%0A    parser.add_argument(%22--debug%22, default=False, action=%22store_true%22,%0A                        help=%22Write out intermediate images%22)%0A    args = parser.parse_args()%0A%0A    if not os.path.isfile(args.input_file):%0A        parser.error(%22%7B%7D not a file%22.format(args.input_file))%0A%0A    if not os.path.isfile(args.mask_file):%0A        parser.error(%22%7B%7D not a file%22.format(args.mask_file))%0A%0A    # Create the output directory if it does not exist.%0A    if not os.path.isdir(args.output_dir):%0A        os.mkdir(args.output_dir)%0A    AutoName.directory = args.output_dir%0A%0A    # Only write out intermediate images in debug mode.%0A    AutoWrite.on = args.debug%0A%0A    # Setup a logger for the script.%0A    log_fname = %22audit.log%22%0A    log_fpath = os.path.join(args.output_dir, log_fname)%0A    logging_level = logging.INFO%0A    if args.debug:%0A        logging_level = logging.DEBUG%0A    logging.basicConfig(filename=log_fpath, level=logging_level)%0A%0A    # Log some basic information about the script that is running.%0A    logging.info(%22Script name: %7B%7D%22.format(__file__))%0A    logging.info(%22Script version: %7B%7D%22.format(__version__))%0A%0A    # Run the analysis.%0A    analyse_file(args.input_file, args.mask_file, args.output_dir)%0A%0Aif __name__ == %22__main__%22:%0A    main()%0A

Add initial script for calculating cell areas