How to resolve the algorithm Hough transform step by step in the J programming language
How to resolve the algorithm Hough transform step by step in the J programming language
Table of Contents
Problem Statement
Implement the Hough transform, which is used as part of feature extraction with digital images. It is a tool that makes it far easier to identify straight lines in the source image, whatever their orientation. The transform maps each point in the target image,
( ρ , θ )
{\displaystyle (\rho ,\theta )}
, to the average color of the pixels on the corresponding line of the source image (in
( x , y )
{\displaystyle (x,y)}
-space, where the line corresponds to points of the form
x cos θ + y sin θ
ρ
{\displaystyle x\cos \theta +y\sin \theta =\rho }
). The idea is that where there is a straight line in the original image, it corresponds to a bright (or dark, depending on the color of the background field) spot; by applying a suitable filter to the results of the transform, it is possible to extract the locations of the lines in the original image. The target space actually uses polar coordinates, but is conventionally plotted on rectangular coordinates for display. There's no specification of exactly how to map polar coordinates to a flat surface for display, but a convenient method is to use one axis for
θ
{\displaystyle \theta }
and the other for
ρ
{\displaystyle \rho }
, with the center of the source image being the origin. There is also a spherical Hough transform, which is more suited to identifying planes in 3D data.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Hough transform step by step in the J programming language
Source code in the j programming language
NB.*houghTransform v Produces a density plot of image y in hough space
NB. y is picture as an array with 1 at non-white points,
NB. x is resolution (width,height) of resulting image
houghTransform=: dyad define
'w h'=. x NB. width and height of target image
theta=. o. (%~ 0.5+i.) w NB. theta in radians from 0 to π
rho=. (4$.$. |.y) +/ .* 2 1 o./theta NB. rho for each pixel at each theta
'min max'=. (,~-) +/&.:*: $y NB. min/max possible rho
rho=. <. 0.5+ h * (rho-min) % max-min NB. Rescale rho from 0 to h and round to int
|.([: <:@(#/.~) (i.h)&,)"1&.|: rho NB. consolidate into picture
)
require 'viewmat'
require 'media/platimg' NB. addon required pre J8
Img=: readimg_jqtide_ jpath '~temp/pentagon.png'
viewmat 460 360 houghTransform _1 > Img
You may also check:How to resolve the algorithm Host introspection step by step in the Ruby programming language
You may also check:How to resolve the algorithm Long literals, with continuations step by step in the jq programming language
You may also check:How to resolve the algorithm Classes step by step in the E programming language
You may also check:How to resolve the algorithm Active Directory/Connect step by step in the Erlang programming language
You may also check:How to resolve the algorithm Identity matrix step by step in the Bash programming language