Skip to main content

A Python-based implementation of the RCC8D ImageJ/Fiji plugin created by Gabriel Landini and David A Randell.

Project description

RCC8D

A Python-based implementation [2] of the RCC8D ImageJ/Fiji plugin created by Gabriel Landini and David A Randell [1]. Read more about the ImageJ/Fiji plugin here.

The purpose of this work is to provide a Python-based version of the ImageJ/Fiji plugin [1] that can be easily integrated with existing Python-based pipelines. It removes the need to install the ImageJ/Fiji software and does not require the user to understand how to use ImageJ/Fiji in order to run the RCC8D analysis.

Example Usage

This example computes the RCC8D relation of each ground truth mask with respect to all predicted masks made for the ground truth image. This is applicable for models such as the Segment Anything model which does not classify the masks that it generates.

from RCC8D.rcc8d import RCC8D
import os
import cv2
import json


def main():
    # argument set-up
    path_to_gt_images = "test_images/gt"
    path_to_pred_images = "test_images/pred"
    eval_out_path = os.path.join("evaluation", "RCC8D_output.json")
    eval_out_json = {}

    # initialise RCC8D class
    rcc8d_ = RCC8D()

    # compute RCC8D relations for every ground truth mask W.R.T every predicted mask
    for gt in os.listdir(path_to_gt_images):
        gt_img_path = os.path.join(path_to_gt_images, gt)
        gt_img = cv2.imread(gt_img_path, cv2.IMREAD_GRAYSCALE)
        eval_out_json[gt_img_path] = {}

        print("Computing RCC8D relations for " + gt)

        for pred in os.listdir(path_to_pred_images):
            if ".png" in pred:
                pred_img_path = os.path.join(path_to_pred_images, pred)
                pred_img = cv2.imread(pred_img_path, cv2.IMREAD_GRAYSCALE)

                result = rcc8d_.compare_images(gt_img, pred_img, mode="RCC8D", attributes=True, details=True)

                eval_out_json[gt_img_path][pred_img_path] = {
                    "gt_attributes": str(result["attributes_x"]),
                    "pred_attributes": str(result["attributes_y"]),
                    "relation_name": result["relation_name"],
                    "relation_number": str(result["relation_number"])
                }

    # write the results to a JSON file
    with open(eval_out_path, 'w') as json_file:
        json.dump(eval_out_json, json_file, indent=4)

    print("Done!")


if __name__ == "__main__":
    main()

To compute the relationship between a single ground truth mask and a single prediction, the following line would be used:

result = rcc8d_.compare_images(gt_img, pred_img, mode="RCC8D", attributes=True, details=True)

Citations

[1] Landini, G., Galton, A., and Randell, D. A. (2013). Discrete mereotopology for spatial reasoning in automated histological image analysis. IEEE Transactions on Pattern Analysis amp; Machine Intelligence, 35(03):568–581.

[2] Porter, V., Gault, R., Styles, I., and Curtis, T. (2024). Contextual Evaluation of Segmentation Models using Spatial Reasoning. Irish Machine Vision and Image Processing Conference (IMVIP).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rcc8d-0.0.1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

RCC8D-0.0.1-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file rcc8d-0.0.1.tar.gz.

File metadata

  • Download URL: rcc8d-0.0.1.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for rcc8d-0.0.1.tar.gz
Algorithm Hash digest
SHA256 44b4ec1c242dd347098d83bf5f3050a81823d48cc2bbbcb5a5b1f6d0b67f1620
MD5 f147a5fc94eb3608fb65b1637a08cdae
BLAKE2b-256 16508b97d52d4ff8e4cd5e69ee9dda7f2a583ad5d5835a0ce929abe19ad7db71

See more details on using hashes here.

File details

Details for the file RCC8D-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: RCC8D-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for RCC8D-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 60447efda151b6ab967d43741d09d0bc0fa807f5d6c51d68088b850619b1d1c9
MD5 fc2c8deb206e1c15d17b325c21bdc231
BLAKE2b-256 6e357d740236d4c62e0bb1175c02276c8996f74f72e8c309ce5364baff28dc99

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page