You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The calculations for r, ri, xd, and yd in vips_hough_line_vote appear to be incorrect, causing curves in the Hough image to be cut off for either low angles at high values of r or high angles at low values of r.
In a test script (below), I was able to address this by:
Scaling and shifting ri to accommodate negative values
Calculatingxd and yd by dividing x and y with the diagonal of the image instead of their respective image dimensions. This ensures r will stay within 1 and the adjusted ri within the bounds of height.
To Reproduce
I discovered this behavior with the following Ruby script. I was using it to clarify my understanding of how the width and height arguments to hough_line should be translated back to values of theta and rho.
What the script does:
Create a 512 by 512 pixel black image with two pixels set to white.
Create a Vips image from the nested array of pixel values; the image is output to a file for debugging
Calculate the Hough space with Vips::Image#hough_line
Calculate the Hough space manually using the changes mentioned under Describe the bug
Output the Hough images and the images highlighting intersections in Hough images to files (examples attached below)
Print intersections to stderr
#!/usr/bin/env ruby# This script creates a 512x512 image with individual pixels set to white## The `points` array is a list of points I was testing to see if they intersect# in the output `hough_line`require"ruby-vips"require"pp"# Check points at different orientations to each other## Only rendering two points at at time for simplicitypoints=[# Corner pixels to test boundaries#[1, 1],#[1, 512],#[512, 1],#[512, 512],# horizontal line#[128, 256],#[384, 256],# vertical line#[256, 128],#[256, 384],# Points where no intersection is found `Vips::Image#hough_line`# points that would produce theta > 135; no intersection is found#[118, 128],#[274, 384],# Pixels at the right edge of the image that would cause theta to be near 180[511,1],[512,512],]# Build the image as an array of zerosimage_array=[[0]] * 512image_array=[image_array] * 512# Change the points to 255 (white)points.eachdo |(x,y)|
row_index=x - 1column_index=y - 1row=image_array[column_index].duprow[row_index]=[255]image_array[column_index]=rowendimage=Vips::Image.new_from_array(image_array)image.write_to_file("test-hough-source.jpeg")# Using a large number of theta steps to ensure pixels overlap in the Hough# space overlaptheta_segments=1800# Using dimensions of the image times 2 to make sure I understand what the# values of rho mean in the output of `hough_line`rho_segments=1024### VIPS CALCULATION#hough_image=image.hough_line(width: theta_segments,height: rho_segments)### MANUAL CALCULATION## Manually find the Hough space for the image using an updated calculation for# rhohough_space_array=[]rho_segments.timesdohough_space_array << [0] * theta_segmentsendsine_values=(0...theta_segments * 2).map{Math.sin(2 * Math::PI * _1 / (2 * theta_segments))}# Store this as a variable for debugging the calculation of `rho_step`_points_sinusoids=points.mapdo |x,y|
# This part of the calculation in `vips_hough_line_vote` needs to be updated# toox_normalized=x / Math.sqrt(2 * 512 ** 2)y_normalized=y / Math.sqrt(2 * 512 ** 2)(0...theta_segments).mapdo |theta_step|
rho_normalized=x_normalized * sine_values[theta_step + theta_segments / 2] + y_normalized * sine_values[theta_step]# Compact and shift `rho_step` to fit in `rho_segments`## For theta 0 - 180, the lower 15% of `rho_segments` will never have a value## Calculating the Hough space for 0 - 360 would populate these valuesrho_step=(rho_normalized * rho_segments).to_i / 2 + (rho_segments / 2)hough_space_array[rho_step][theta_step] += 1rho_stependendhough_space_buffer="".encode("BINARY")hough_space_array.eachdo |row|
hough_space_buffer << row.pack("C*")endhough_adjusted_image=Vips::Image.new_from_memory(hough_space_buffer,theta_segments,rho_segments,1,"uchar")[["default",hough_image],["adjusted",hough_adjusted_image]].eachdo |name,image|
image_any_votes=image > 0image_any_votes.write_to_file("test-hough-pixels-#{name}.jpeg")image_intersections=image > 1image_intersections.write_to_file("test-hough-intersections-#{name}.jpeg")# Outputting 5 values because the high resolution for theta means there can be# more than one intersection in Hough space for one line
$stderr.puts"#{name}:"
$stderr.putsimage_intersections.max(size: 5,x_array: true,y_array: true,out_array: true).inspectend
Expected behavior
Curves in Hough space should not be cut off.
Actual behavior
Curves in Hough spaces are cut off around 45 and 135 degrees.
Screenshots
Pixels at (118, 128) and (274, 384) creating a line with theta = 148 Vips::Image#hough_line
Manual calculation
Pixels at (511, 1) and (512, 512) creating a line with theta near 180; demonstrates curves being cut off at low angles Vips::Image#hough_line
Manual calculation
🙏🏼Thanks for reading.
The text was updated successfully, but these errors were encountered:
Bug report
Please let me know if you need anything else.
Environment
Describe the bug
The calculations for
r
,ri
,xd
, andyd
invips_hough_line_vote
appear to be incorrect, causing curves in the Hough image to be cut off for either low angles at high values ofr
or high angles at low values ofr
.In a test script (below), I was able to address this by:
ri
to accommodate negative valuesxd
andyd
by dividingx
andy
with the diagonal of the image instead of their respective image dimensions. This ensuresr
will stay within 1 and the adjustedri
within the bounds ofheight
.To Reproduce
I discovered this behavior with the following Ruby script. I was using it to clarify my understanding of how the
width
andheight
arguments tohough_line
should be translated back to values of theta and rho.What the script does:
Vips::Image#hough_line
Expected behavior
Curves in Hough space should not be cut off.
Actual behavior
Curves in Hough spaces are cut off around 45 and 135 degrees.
Screenshots
Pixels at (118, 128) and (274, 384) creating a line with theta = 148

Vips::Image#hough_line
Manual calculation

Pixels at (511, 1) and (512, 512) creating a line with theta near 180; demonstrates curves being cut off at low angles

Vips::Image#hough_line
Manual calculation

🙏🏼Thanks for reading.
The text was updated successfully, but these errors were encountered: