pylsd-nova


Namepylsd-nova JSON
Version 1.2.1 PyPI version JSON
download
home_pagehttps://github.com/AndranikSargsyan/pylsd-nova
Summarypylsd-nova is a python binding for LSD - Line Segment Detector
upload_time2023-04-15 16:02:21
maintainer
docs_urlNone
authorAndranik Sargsyan
requires_python
licenseBSD
keywords lsd
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            pylsd-nova
=============

### 1. Introduction

pylsd-nova is a python binding for [LSD - Line Segment Detector](http://www.ipol.im/pub/art/2012/gjmr-lsd/).

This is a fork from original [pylsd binding](https://github.com/primetang/pylsd/). This fork works for Python 3 and adds the ability to change lsd parameters from python call. 

### 2. Install

This package uses distutils, which is the default way of installing python modules. For installing by cloning the repository you can run the following commands:
```
git clone https://github.com/AndranikSargsyan/pylsd-nova.git
cd pylsd-nova
pip install .
```

Or install directly through `pip`:
```
pip install pylsd-nova
```

### 3. Usage

You can use the package by importing like  `from pylsd import lsd`, and calling `segments = lsd(img)` by optionally passing other lsd parameters mentioned below. `img` is a Grayscale Image (`H x W` numpy.ndarray), and the return value `segments` contains detected line segments.

`segments` is an `N x 5` numpy.ndarray. Each row represents a straight line. The 5-dimensional row format is:

```
[point1.x, point1.y, point2.x, point2.y, width]
```

These are the parameters of lsd, which can be changed through keyword arguments of lsd call:


* `scale (float)`: Scale the image by Gaussian filter to 'scale'.

* `sigma_scale (float)`: Sigma for Gaussian filter is computed as `sigma = sigma_scale / scale`.

* `quant (float)`: Bound to the quantization error on the gradient norm.

* `ang_th (float)`: Gradient angle tolerance in degrees.

* `eps (float)`: Detection threshold, `-log10(NFA)`.

* `density_th (float)`: Minimal density of region points in rectangle.

* `n_bins (int)`: Number of bins in pseudo-ordering of gradient modulus.

* `max_grad (float)`: Gradient modulus in the highest bin. The default value corresponds to the highest gradient modulus on images with gray levels in [0,255].


You can use it just like the following code ([here is the link to examples](https://github.com/AndranikSargsyan/pylsd-nova/tree/master/example)):

* by using cv2 module

```python
import cv2
import numpy as np
import os
from pylsd import lsd

full_name = 'car.jpg'
folder, img_name = os.path.split(full_name)
img = cv2.imread(full_name, cv2.IMREAD_COLOR)
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

segments = lsd(img_gray, scale=0.5)

for i in range(segments.shape[0]):
    pt1 = (int(segments[i, 0]), int(segments[i, 1]))
    pt2 = (int(segments[i, 2]), int(segments[i, 3]))
    width = segments[i, 4]
    cv2.line(img, pt1, pt2, (0, 0, 255), int(np.ceil(width / 2)))

cv2.imwrite(os.path.join(folder, 'cv2_' + img_name.split('.')[0] + '.jpg'), img)
```

* by using PIL(Image) module

```python
import numpy as np
import os
from PIL import Image, ImageDraw
from pylsd import lsd

full_name = 'house.png'
folder, img_name = os.path.split(full_name)
img = Image.open(full_name)
img_gray = np.asarray(img.convert('L'))

segments = lsd(img_gray, scale=0.5)

draw = ImageDraw.Draw(img)
for i in range(segments.shape[0]):
    pt1 = (int(segments[i, 0]), int(segments[i, 1]))
    pt2 = (int(segments[i, 2]), int(segments[i, 3]))
    width = segments[i, 4]
    draw.line((pt1, pt2), fill=(0, 0, 255), width=int(np.ceil(width / 2)))

img.save(os.path.join(folder, 'PIL_' + img_name.split('.')[0] + '.jpg'))
```

The following is the result:

* car.jpg by using cv2 module

![](https://github.com/AndranikSargsyan/pylsd-nova/blob/master/example/car.jpg)

![](https://github.com/AndranikSargsyan/pylsd-nova/blob/master/example/cv2_car.jpg)

* house.png by using PIL(Image) module

![](https://github.com/AndranikSargsyan/pylsd-nova/blob/master/example/house.png)

![](https://github.com/AndranikSargsyan/pylsd-nova/blob/master/example/PIL_house.jpg)



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/AndranikSargsyan/pylsd-nova",
    "name": "pylsd-nova",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "LSD",
    "author": "Andranik Sargsyan",
    "author_email": "and.sargsyan@yahoo.com",
    "download_url": "https://files.pythonhosted.org/packages/8b/3b/1abd072eb4586f31e7ebe8f95a58fbf64a84fedf9a3ec21a982ae73c9605/pylsd-nova-1.2.1.tar.gz",
    "platform": null,
    "description": "pylsd-nova\n=============\n\n### 1. Introduction\n\npylsd-nova is a python binding for [LSD - Line Segment Detector](http://www.ipol.im/pub/art/2012/gjmr-lsd/).\n\nThis is a fork from original [pylsd binding](https://github.com/primetang/pylsd/). This fork works for Python 3 and adds the ability to change lsd parameters from python call. \n\n### 2. Install\n\nThis package uses distutils, which is the default way of installing python modules. For installing by cloning the repository you can run the following commands:\n```\ngit clone https://github.com/AndranikSargsyan/pylsd-nova.git\ncd pylsd-nova\npip install .\n```\n\nOr install directly through `pip`:\n```\npip install pylsd-nova\n```\n\n### 3. Usage\n\nYou can use the package by importing like  `from pylsd import lsd`, and calling `segments = lsd(img)` by optionally passing other lsd parameters mentioned below. `img` is a Grayscale Image (`H x W` numpy.ndarray), and the return value `segments` contains detected line segments.\n\n`segments` is an `N x 5` numpy.ndarray. Each row represents a straight line. The 5-dimensional row format is:\n\n```\n[point1.x, point1.y, point2.x, point2.y, width]\n```\n\nThese are the parameters of lsd, which can be changed through keyword arguments of lsd call:\n\n\n* `scale (float)`: Scale the image by Gaussian filter to 'scale'.\n\n* `sigma_scale (float)`: Sigma for Gaussian filter is computed as `sigma = sigma_scale / scale`.\n\n* `quant (float)`: Bound to the quantization error on the gradient norm.\n\n* `ang_th (float)`: Gradient angle tolerance in degrees.\n\n* `eps (float)`: Detection threshold, `-log10(NFA)`.\n\n* `density_th (float)`: Minimal density of region points in rectangle.\n\n* `n_bins (int)`: Number of bins in pseudo-ordering of gradient modulus.\n\n* `max_grad (float)`: Gradient modulus in the highest bin. The default value corresponds to the highest gradient modulus on images with gray levels in [0,255].\n\n\nYou can use it just like the following code ([here is the link to examples](https://github.com/AndranikSargsyan/pylsd-nova/tree/master/example)):\n\n* by using cv2 module\n\n```python\nimport cv2\nimport numpy as np\nimport os\nfrom pylsd import lsd\n\nfull_name = 'car.jpg'\nfolder, img_name = os.path.split(full_name)\nimg = cv2.imread(full_name, cv2.IMREAD_COLOR)\nimg_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n\nsegments = lsd(img_gray, scale=0.5)\n\nfor i in range(segments.shape[0]):\n    pt1 = (int(segments[i, 0]), int(segments[i, 1]))\n    pt2 = (int(segments[i, 2]), int(segments[i, 3]))\n    width = segments[i, 4]\n    cv2.line(img, pt1, pt2, (0, 0, 255), int(np.ceil(width / 2)))\n\ncv2.imwrite(os.path.join(folder, 'cv2_' + img_name.split('.')[0] + '.jpg'), img)\n```\n\n* by using PIL(Image) module\n\n```python\nimport numpy as np\nimport os\nfrom PIL import Image, ImageDraw\nfrom pylsd import lsd\n\nfull_name = 'house.png'\nfolder, img_name = os.path.split(full_name)\nimg = Image.open(full_name)\nimg_gray = np.asarray(img.convert('L'))\n\nsegments = lsd(img_gray, scale=0.5)\n\ndraw = ImageDraw.Draw(img)\nfor i in range(segments.shape[0]):\n    pt1 = (int(segments[i, 0]), int(segments[i, 1]))\n    pt2 = (int(segments[i, 2]), int(segments[i, 3]))\n    width = segments[i, 4]\n    draw.line((pt1, pt2), fill=(0, 0, 255), width=int(np.ceil(width / 2)))\n\nimg.save(os.path.join(folder, 'PIL_' + img_name.split('.')[0] + '.jpg'))\n```\n\nThe following is the result:\n\n* car.jpg by using cv2 module\n\n![](https://github.com/AndranikSargsyan/pylsd-nova/blob/master/example/car.jpg)\n\n![](https://github.com/AndranikSargsyan/pylsd-nova/blob/master/example/cv2_car.jpg)\n\n* house.png by using PIL(Image) module\n\n![](https://github.com/AndranikSargsyan/pylsd-nova/blob/master/example/house.png)\n\n![](https://github.com/AndranikSargsyan/pylsd-nova/blob/master/example/PIL_house.jpg)\n\n\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "pylsd-nova is a python binding for LSD - Line Segment Detector",
    "version": "1.2.1",
    "split_keywords": [
        "lsd"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8b3b1abd072eb4586f31e7ebe8f95a58fbf64a84fedf9a3ec21a982ae73c9605",
                "md5": "61511a7a542af2c77ff8590fb2b9c73b",
                "sha256": "ec8cf78c7059034e151c2cd9c069390cf7540bf7c60b2057c30f917acacd0de8"
            },
            "downloads": -1,
            "filename": "pylsd-nova-1.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "61511a7a542af2c77ff8590fb2b9c73b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 172340,
            "upload_time": "2023-04-15T16:02:21",
            "upload_time_iso_8601": "2023-04-15T16:02:21.799404Z",
            "url": "https://files.pythonhosted.org/packages/8b/3b/1abd072eb4586f31e7ebe8f95a58fbf64a84fedf9a3ec21a982ae73c9605/pylsd-nova-1.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-15 16:02:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "AndranikSargsyan",
    "github_project": "pylsd-nova",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pylsd-nova"
}
        
Elapsed time: 0.06639s