Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hough transform feature request #85

Open
dirtbirb opened this issue Jan 31, 2017 · 6 comments
Open

Hough transform feature request #85

dirtbirb opened this issue Jan 31, 2017 · 6 comments

Comments

@dirtbirb
Copy link

I've used mahotas for detecting/labeling objects, and now need to add a Hough transform element to it. I'll probably use OpenCV for now, but to reduce dependencies I'd like to stick with only mahotas. I saw that Hough transforms were on the possible features list, and just wanted to make an issue to formally express interest in that.

Please close this issue if Hough transforms are no longer a planned feature, or if the issue queue isn't the right place to request this!

@luispedro
Copy link
Owner

It's not, at the moment, a priority for me (although I would gladly accept a patch), but I will leave the issue open for future reference.

@jasson2001
Copy link

Mr luispedro 👍
Frist , thank you for your excellent work! I am very glad to join your project!
Recently, I help a kindly friend to do some thing- Hough transforms , using in detect line in a image,
Could I pull my code? Can you interview my code?
Thank you again!

@jasson2001
Copy link

import math
import mahotas as mh
import mahotas.demos
import numpy as np
import pylab as plt
import matplotlib
matplotlib.use('TkAgg')

import pylab

class Line():
def init(self,r,angle):
self.r = r
self.angle = angle
def eq(self, other):
if self.r == other.r and self.angle == other.angle:
return True
else:
return False
def hash(self):
result = 31 + int(self.r)
result = 31 * result + int(self.angle * 100)
#print result
return result

class Counter(dict):
def missing(self, key):
return 0

class LineDetectorByHough:
countersDICT = Counter(dict())
def init(self):
pass

def find(self,img):
    rows, cols = img.shape
    print 'rows,cols=', rows, cols
    points = 0
    for x in range(0, rows):
        for y in range(0, cols):
            if (img[x, y] == 1):
                points = points + 1
                for angle in np.arange(0, 2 * np.pi, 2 * np.pi / 40):
                    # print 'angel=',x, y, angel
                    angle = round(angle, 2)
                    angle = angle % round(np.pi, 2)
                    r = round(self.calcR(x, y, angle),1)
                    print 'r,angel=', r, angle
                    self.countersDICT[Line(r, angle)] += 1
    print "points=", points
    print "line (r ,angle) count"

    for (k, v) in self.countersDICT.items():
        if(v > 2):
            print "line ", k.r, k.angle, str(v)  # %(2 * np.pi)
def calcR(self,x,y,angle):
    return x* math.cos(angle) + y * math.sin(angle)
def mask(self,img,x0,y0,template):
    val = 0
    for x in range(-1, 1):
        for y in range(-1, 1):
            val = val +  template[x+1][y+1] * img[x0+x][y0+y]
    return val / 9

@jasson2001
Copy link

This is test code:

-- coding: utf-8 --

import unittest
import math
import numpy as np
import mahotas as mh

import matplotlib
matplotlib.use('TkAgg')

import matplotlib.pyplot as plt
from skimage import data,transform

import pylab

from LineDetectorByHough import LineDetectorByHough
from LineDetectorByHough import Line

class TestLineDetectorByHough(unittest.TestCase):
def test_simpleImg_hough_detect(self):
img = np.zeros((80, 80), bool)
img[6,:] = 1

    pylab.imshow(img)
    pylab.show()
    c = LineDetectorByHough()
    c.find(img)

@luispedro
Copy link
Owner

Thanks, I would be happy to help you, but this is very hard to evaluate like this as the formatting is all messed up.

Can you please submit this as a pull request?

@jasson2001
Copy link

Thank you again,
I have submit my code with unit test, and create a pull request,
but CI report error :
/usr/include/features.h:162:0: note: this is the location of the previous definition

define _XOPEN_SOURCE 700

^
In file included from mahotas/numpypp/array.hpp:17:0,
from mahotas/_histogram.cpp:10:
mahotas/numpypp/numpy.hpp:11:33: fatal error: numpy/ndarrayobject.h: No such file or directory
#include <numpy/ndarrayobject.h>
^
compilation terminated.
error: command 'gcc' failed with exit status 1
make: *** [debug] Error 1
The command ".travis/travis_install.sh" failed and exited with 2 during .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants