UNIT- II
UNIT- II
ℎ𝑖 𝑓
=
ℎ𝑜 𝑑𝑜
Q2. A pinhole camera has an image sensor of 24mm × 36mm. The
camera captures an image of a 1.5m tall object that appears 30mm
tall on the image sensor. The object is placed 3m away from the
camera.
Find the focal length of the camera.
Problem 2: Homography Matrix Calculation
A planar object undergoes a homography transformation, where a point P(2, 3) in the original image gets
mapped to P'(8, 6) in the transformed image. Given the homography matrix:
2 0 0
𝐻= 0 2 0
0 0 1
Find the mapped coordinates of the point Q(4, 5).
# loading image
img = mahotas.imread('/content/Dog.jpg')
# filtering image
img = img[:, :, 0]
print("Image")
Mahotas – Highlighting Image Maxima
Syntax : img.mean()
Argument : It takes no argument
Return : It returns float32
Mahotas – Element Structure for Dilating Image
In this article we will see how we can set the element structure of the dilate
of image in mahotas. Dilation adds pixels to the boundaries of objects in an
image, while erosion removes pixels on object boundaries. The number of
pixels added or removed from the objects in an image depends on the size
and shape of the structuring element used to process the image.
# loading image
img = mahotas.imread(‘image')
# otsu method
T_otsu = mahotas.otsu(img)
Mahotas – Cropping Image
In this article we will see how we can get the image cropped to the
bounding box in mahotas. We can get image bounding box with the help of
bbox method.
# importing required libraries
import mahotas
import numpy as np
from pylab import gray, imshow, show
import os
# loading image
img = mahotas.imread(‘image')
# filtering image
img = img[:, :, 0]
# otsu method
T_otsu = mahotas.otsu(img)
# image values should be greater than otsu
value
img = img > T_otsu
# showing image
imshow(img)
show()
# crop to bbox
new_img = mahotas.croptobbox(img)
# showing image
imshow(new_img)
show()
# Create figure and subplots
fig, axes = plt.subplots(1, 3, figsize=(12, 4))
ax = axes.ravel()
# showing image
imshow(img)
show()
# erode structure
es = np.array([
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]], bool)
# dilating image
dilate_img = mahotas.morph.dilate(img, es)
def transform_function(r):
s = 2 * r # Transformation: Multiply each pixel by 2
return s
# Convert to grayscale
grayscale = rgb2gray(original[..., :3]) # Avoids
deprecation warning
Solution:
Here we see that each point is indicated by two numbers. Hence this is the case of two dimensional coordinate
system.
Solution:
Here the point is indicated by three values hence this is a case of 3D Cartesian
Coordinate System. In 3D Cartesian Coordinate System, the distance of the
point from the origin is given as
√(x2 + y2 + z2)
Solution:
Solution:
Q2: Find the slope of the line joining the points (-1, 4) and (2, -3)
Q3: Find the equation of a line using slope form of a line which passes through
point (3,4) and slope is 2/3.
Q4: Find the coordinates of a point which is the midpoint of a line joining the
points (1, 3) and (-3, 4).
Q5: Locate Points (-5, 6), (2, -3), (1, 2) and (-1, 0) in Cartesian System.
"Perspective correction" and "perspective
rectification“
Essentially mean the same thing: the process of digitally adjusting an image to eliminate
distortion caused by the angle at which a photo was taken, making lines that appear to
converge in the image appear straight and parallel in the corrected version, often used
to straighten up buildings or objects photographed from a low angle; it's achieved
through a mathematical transformation known as a "projective transformation" in image
editing software.
Key points about perspective correction/rectification:
•What it corrects:
•When you take a picture from a non-parallel angle to a flat surface, lines in the image
can appear to converge towards a vanishing point, creating a distorted
perspective. Perspective correction aims to "un-distort" this effect, making the lines
appear straight and parallel as they would in reality.
•How it works:
•Software like Photoshop utilizes a "perspective warp" tool that allows you to define
reference points on the image (like the corners of a building) and then mathematically
adjust the pixels to create a corrected image where the lines are straight.
Applications:
•Untitled41.ipynb - Colab