Methodology:

Image Pre-processing:
The initial step involved loading the provided images and ensuring uniformity in their dimensions by resizing.
from matplotlib import pyplot as plt
import cv2

# Load the two images
img1 = cv2.imread('/mnt/data/IMG1.jpg', cv2.IMREAD_GRAYSCALE)
img2 = cv2.imread('/mnt/data/IMG2.jpg', cv2.IMREAD_GRAYSCALE)

# Resize the images if they are not of the same size
if img1.shape != img2.shape:
img2 = cv2.resize(img2, (img1.shape[1], img1.shape[0]))

# Display the images
fig, ax = plt.subplots(1, 2, figsize=(12, 6))

ax[0].imshow(img1, cmap='gray')
ax[0].set_title('Image 1')
ax[0].axis('off')

ax[1].imshow(img2, cmap='gray')
ax[1].set_title('Image 2')
ax[1].axis('off')

plt.tight_layout()
plt.show()
image.png
Feature Detection & Matching:
Utilizing the ORB (Oriented FAST and Rotated BRIEF) algorithm, distinct keypoints in both images were pinpointed. These keypoints, representative of unique image features, were then matched between the two images using a Brute-Force Matcher. This step was pivotal in determining corresponding points in the two images, illustrating the car's movement.
# Initialize ORB detector
orb = cv2.ORB_create()

# Find keypoints and descriptors with ORB
keypoints1, descriptors1 = orb.detectAndCompute(img1, None)
keypoints2, descriptors2 = orb.detectAndCompute(img2, None)

# Create BFMatcher object
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)

# Match descriptors
matches = bf.match(descriptors1, descriptors2)

# Sort matches based on their distances
matches = sorted(matches, key=lambda x: x.distance)

# Draw the matches
img_matches = cv2.drawMatches(img1, keypoints1, img2, keypoints2, matches[:50], None, flags=cv2.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS)

# Display the matches
plt.figure(figsize=(14, 7))
plt.imshow(img_matches)
plt.title('Key Point Matches')
plt.axis('off')
plt.show()
image.png
The average displacement of the car between the two images is approximately:
Δx≈−10.44 pixels (in the horizontal direction)
y≈−23.62 pixels (in the vertical direction)
The negative sign indicates the direction of movement. For instance, a negative Δx suggests that the car moved to the left, and a negative Δy implies an upward movement.
Motion Estimation:
With the matched keypoints, we calculated the average displacement, signifying the car's movement in the image domain.
Reference Object-based Physical Distance Calculation:
A vital step was identifying a consistent reference object in both images - a white pipe cap on the road. This object's diameter in the image was gauged, and with its known real-world diameter (assumed 15 cm), we derived a pixel-to-real-world ratio. This conversion metric was essential to translate the car's pixel-based movement into an actual physical distance.
image.png
The corrected detection of the white pipe cap (south of the car) is highlighted with a green contour in the displayed region of interest. Based on our refined detection, the diameter of the pipe cap is approximately 19 pixels.
Given that the actual diameter of the pipe cap is assumed to be 0.15 meters (or 1515 cm), we can compute the new pixel-to-real-world ratio.
Pixel-to-Real-World Ratio = (0.15 meters / 0.19 pixels)​
Using this updated ratio, we can convert the car's movement from pixels to meters.
# Compute the updated pixel-to-real-world ratio
pixel_to_real_world_ratio_corrected = 0.15 / diameter_pixels_corrected

# Convert the car's movement from pixels to meters using the updated ratio
dx_meters_corrected = avg_dx * pixel_to_real_world_ratio_corrected
dy_meters_corrected = avg_dy * pixel_to_real_world_ratio_corrected

dx_meters_corrected, dy_meters_corrected
RESULT
(-0.08245665084712893, -0.18649515913735973)
Δx≈−0.0825 meters (or -8.25 cm) in the horizontal direction.
Δy≈−0.1865 meters (or -18.65 cm) in the vertical direction.
Speed Estimation:
Let's assume an average shot-to-shot time of 1 second. If you know the exact time or have a specific iPhone model in mind, please let me know, and I can adjust accordingly.
Given this interval, we can compute the speed of the car in both the x and y directions using the formula:
Speed= Distance/Time
# Time interval between the two frames (in seconds)
time_interval = 1.0 # Assuming 1 second for shot-to-shot time

# Compute the speed of the car in both x and y directions
speed_x = dx_meters_corrected / time_interval
speed_y = dy_meters_corrected / time_interval

# Compute the overall speed (magnitude) of the car
overall_speed = np.sqrt(speed_x**2 + speed_y**2)

speed_x, speed_y, overall_speed
RESULT
(-0.08245665084712893, -0.18649515913735973, 0.20391062662498602)

The estimated speed of the car based on the displacement between the two images and the assumed 1-second interval is:
Speed in the horizontal direction (x): −0.0825−0.0825 meters/second (or −8.25−8.25 cm/second). The negative sign indicates movement to the left.
Speed in the vertical direction (y): −0.1865−0.1865 meters/second (or −18.65−18.65 cm/second). The negative sign indicates upward movement.
Overall speed (magnitude): 0.20390.2039 meters/second (or 20.3920.39 cm/second).
The estimated speed of the car is approximately 0.4560.456 miles per hour (mph). This is a relatively slow speed, which is consistent with the short displacement observed between two quickly taken consecutive images, however is not very plausible given I knew the speed to be faster.

Detailed Findings:

Keypoint Detection & Matching: The ORB algorithm effectively highlighted distinct keypoints in both images, and subsequent matching illustrated the car's evident shift between the images. The car's movement direction—leftward and slightly upward—was discerned from the negative displacements in the horizontal and vertical directions, respectively.
Reference Object Utilization: The pipe cap's detection was crucial. Measuring its image diameter (approximately 19 pixels) and juxtaposing it with its real-world diameter provided a pixel-to-real-world conversion ratio. This ratio was imperative in translating the car's average displacement of -10.44 pixels (horizontal) and -23.62 pixels (vertical) to real-world measurements of -8.25 cm and -18.65 cm, respectively.
Speed Calculation: With the time interval between the images assumed as 1 second, the car's speed was estimated to be approximately 20.39 cm/second.

Conclusions:

Reference Object Dimensions: The real-world dimensions of the white pipe cap were assumed to be 15 cm. If this assumption is incorrect, it will directly impact the pixel-to-real-world ratio and subsequently the speed estimation. A more accurate measurement of the pipe cap's diameter would improve the result.
Key Point Matching: While ORB is robust, the quality of matched keypoints can still vary. Not all matches may correspond to the car's motion; some could be related to other moving or static objects, or even noise. A more refined selection of keypoints or using a different feature matching technique could yield better results.
Time Interval: We assumed a 1-second interval between the two photos. If this interval is shorter or longer than assumed, it would affect the speed calculation. Verifying the exact shot-to-shot time or considering the phone's specific model and settings would be beneficial.
Car's Actual Motion: If the car was slowing down, accelerating, or almost stationary during the short time between the two shots, this would influence the result. However, for a car moving at a constant speed on a road, the estimated speed indeed seems too low.
Camera Angle and Perspective: If the images were taken from an angle, especially if the car is moving diagonally or towards/away from the camera, the 2D displacement in the images might not fully capture the car's actual 3D motion. Accounting for perspective and depth would provide a more accurate speed estimation.

Edge Detection in Color Images: A Short Report

Introduction

The goal of the program was to develop a generalizable edge detection algorithm that identifies the boundaries of objects of a particular color in diverse color images. Special emphasis was put on modularity, efficiency, and user-centric design.

Special Features

Color Isolation: The program uses HSV color space for more accurate color isolation. It allows for flexibility in specifying a range of hues for targeted objects.
Morphological Refinement: Apart from using the Canny edge detection algorithm, the program employs morphological operations to refine the detected edges, thereby enhancing the accuracy and visual clarity.
User-Centric Design: The program allows for visual overlays of the detected edges on the original images, enhancing user interpretability. Additionally, it allows for adjustable line thickness for better visibility.

Findings

Color Isolation is Key: One of the first observations was the importance of accurate color isolation for effective edge detection. A poorly isolated object led to suboptimal edge detection results.
Importance of Refinement: The initial edge detection often included noise and false positives. Morphological operations were crucial in refining these edges for a more accurate representation.
User Feedback: The initial version of the edge overlays had thin lines, making them hard to see. This was improved based on user feedback, emphasizing the importance of user-centric design.

Conclusions

The program successfully achieves its goal of detecting the boundaries of objects of specific colors in color images. It aligns well with the principles of software optimization, particularly in terms of modularity, efficiency, and user satisfaction. However, there's room for further improvements, such as incorporating machine learning for more adaptive edge detection.
The approach taken in this program could serve as a blueprint for more complex image processing tasks, demonstrating the value of effective algorithm optimization and user-centric design.
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.