Skip to main content

ridge / line detection algorithm

Project description

ridge_detection

This package implements and extends the ridge / line detection algorithm described in:

Steger, C., 1998. An unbiased detector of curvilinear structures. IEEE Transactions on Pattern Analysis and Machine Intelligence, 20(2), pp.113–125.

It is basically the translation from java to python of https://github.com/thorstenwagner/ij-ridgedetection. For more informations about the params visit "https://imagej.net/Ridge_Detection".

Please pay attention that we removed some part of the code and some parameters

HOW RUN IT

Starting form the version 2.0.0 a GUI is provided. This is the running main

from ridge_detection.gui import create_win

if __name__ == "__main__":
    create_win()

The core part of the tool is the LineDetector class. That is callable from config file (see below) or with dict variable which must have the same format

An example script is:

from ridge_detection.lineDetector import LineDetector
from ridge_detection.params import Params,load_json
from ridge_detection.basicGeometry import reset_counter
from ridge_detection.helper import displayContours,save_to_disk
from argparse import ArgumentParser
from datetime import datetime
from PIL import Image
from  mrcfile import open as mrcfile_open


def run():
    start=datetime.now()
    parser = ArgumentParser("ridge detection parser tool")
    parser.add_argument(dest="config_filename",type=str, nargs='?',help="name of the config_file to use. Default value is 'example_config.json'")
    args=parser.parse_args()
    config_filename = args.config_filename if args.config_filename is not None else "example_config.json"
    json_data=load_json(config_filename)
    params = Params(config_filename)

    try:
        img=mrcfile_open(json_data["path_to_file"]).data
    except ValueError:
        img=Image.open(json_data["path_to_file"])

    detect = LineDetector(params=config_filename)
    result = detect.detectLines(img)
    resultJunction =detect.junctions
    out_img,img_only_lines = displayContours(params,result,resultJunction)      
    if params.get_saveOnFile() is True:
        save_to_disk(out_img,img_only_lines)

    print(" TOTAL EXECUTION TIME: " + str(datetime.now()-start))

if __name__ == "__main__":
    run()

From the command line:

python main.py name_your_config_file.json

EXAMPLE CONFIG FILE

It has to be a json format

{
    "path_to_file": "../example.tif",
    "mandatory_parameters": {
        "Sigma": 3.39,
        "Lower_Threshold": 0.34,
        "Upper_Threshold": 1.02,
        "Maximum_Line_Length": 0,
        "Minimum_Line_Length": 0,
        "Darkline": "LIGHT",
        "Overlap_resolution": "NONE"
    },

    "optional_parameters": {
        "Line_width": 10.0,
        "High_contrast": 200,
        "Low_contrast": 80
    },

    "further_options": {
        "Correct_position": true,
        "Estimate_width": true,
        "doExtendLine": true,
        "Show_junction_points": true,
        "Show_IDs": false,
        "Display_results": true,
        "Preview": true,
        "Make_Binary": false,
        "save_on_disk": true
    }
}

PARAMETER SELECTION

There are three parameters which have to be specified. These are the mandatory parameters. The optional parameters can be used to estimate the mandatory parameters

MANDATORY PARAMETERS:

SIGMA --> Determines the sigma for the derivatives. It depends on the line width

LOWER THRESHOLD --> Line points with a response smaller as this threshold are rejected

UPPER THRESHOLD --> Line points with a response larger as this threshold are accepted.

DARKLINE (true/false) --> This parameter determines whether dark or bright lines are extracted.

OVERLAP RESOLUTION (None/Slope) --> You can select a method to attempt automatic overlap resolution. The accuracy of this method will depend on the structure of your data.

  • NONE --> The default behavior: no assumption of overlap is made. Any point of potential intersection will be treated as an end point for the ridges involved.
  • SLOPE --> This method makes the assumption that when two ridges overlap, it is more likely that they will continue on their path than make turns. This is best suited to datasets with brief periods of overlap! If two ridges have a significant portion of overlap, the accuracy of this method will rapidly diminish.

OPTIONAL PARAMETERS:

They are used to estimate the mandatory parameters. It is able starting from the version 3.0.0

The formula are written using latex. You cannot see them on git.

LINE WIDTH (w) --> The line diameter in pixels. It estimates the mandatory parameter 'Sigma' by:

HIGH CONTAST (Bupper) --> Highest grayscale value of the line. It estimates the mandatory parameter 'Upper threshold' by:

LOW CONTAST (Blow) --> Lowest grayscale value of the line. It estimates the mandatory parameter 'Lower threshold' by:

FURTHER OPTIONS (True/False)

CORRECTION POSITION --> Correct the line position if it has different contrast on each side of it

ESTIMATE WIDTH: If this option is selected the width of the line is estimated.

SHOW JUNCTION POINTS: If this option is selected the junctions points will be displayed.

SHOW IDs: The ID of each line will be shown.

DISPLAY RESULTS: If this option is selected, all contours and junctions are filled into a results table.

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

ridge_detection-3.0.0.tar.gz (80.2 kB view details)

Uploaded Source

Built Distribution

ridge_detection-3.0.0-py3-none-any.whl (89.2 kB view details)

Uploaded Python 3

File details

Details for the file ridge_detection-3.0.0.tar.gz.

File metadata

  • Download URL: ridge_detection-3.0.0.tar.gz
  • Upload date:
  • Size: 80.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for ridge_detection-3.0.0.tar.gz
Algorithm Hash digest
SHA256 32b9b612f39662d78bbcaa06514233c742e1611beb0f6dc5edd449ca7055abd8
MD5 b02471a455e67eac5524d46a34239711
BLAKE2b-256 7e8945e4301c77e106ed11f71e7563c16fa0ba0b336a906996d7c04aebd777e6

See more details on using hashes here.

File details

Details for the file ridge_detection-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: ridge_detection-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 89.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for ridge_detection-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e04b98a6b5edd25251e35e08574ac958cb0bd120f683cf4a07f9b44f9771ee8
MD5 1120b65ffef6f8364ea3b794c2b19718
BLAKE2b-256 fd9784b3ea1cd208a83856b98b689e29fbc6dd3afee4dccd5da47cc76d128f10

See more details on using hashes here.

Supported by

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