Issue in GLCM directions - image-processing

I am trying to calculate the texture features of my 1 image using GLCM. Now if I use these properties properties = ['contrast', 'energy','ASM', 'homogeneity', 'correlation', 'dissimilarity'] and calculate GLCM in 4 direction angles like [0, np.pi / 4, np.pi / 2, 3 * np.pi / 4] then I get 4 *6=24 feature values. Now my professor is saying 24 features are not enough for the feature selection so calculate GLCM in more directions to get more feature values like previously my directions were [0, 45,90,135] now he is asking me to calculate in [120, 180, 270], etc just to get more features. But everywhere on google I have seen people are calculating GLCM in the standard four directions that is [0, np.pi / 4, np.pi / 2, 3 * np.pi / 4] so is this correct if I calculate GLCM in the other directions which he mentioned?

Related

Determine adjustment factor for projecting 2D image with FOV from 3D point cloud which is constructed using different FOV

I am trying to project a 2D image from a 3D point cloud. Herein, the 3D point cloud is constructed using RGB and Depth images whose FOV is 120 degree. Once the 3D point cloud is constructed, I wanted to reproject a 2D image from it using a FOV 80 degree. The resolution of the images used for building 3D point cloud and the reprojected 2D image are same [width: 1820, height: 940].
I calculated the intrinsic matrix by following the below steps
The camera model used here is PinHole.
Step 1: Calculating focal lengths fx and fy
hfov = fov / 360. * 2. * np.pi
fx = img_w / (2. * np.tan(hfov / 2.))
vfov = 2. * np.arctan(np.tan(hfov / 2) * img_h / img_w)
fy = img_h / (2. * np.tan(vfov / 2.))
* fx and fy are in pixel length
Step 2: Calculating image centers u0, v0
u0, v0 = img_w / 2, img_h / 2
Step 3: Form the matrix
[[fx, 0, u0, 0],
[0, fy, v0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]]
I used this intrinsic matrix and the extrinsic matrix (calculated from x,y,z, roll, ptich and yaw) to reproject the 2D image with 80 degree FOV using Open3D api from 3D point cloud which was constructed using 120 degree FOV.
When I follow the above steps, I ended up with a 2D image which is zoomed in a lot than expected. However, if I reproject the 2D image with 120 degree FOV then the resulting image is almost close to the expectation (some extra regions are projected but camera to plane distance is perfect).
You can find the sample output below
Reprojected image with FOV 80 degree from the point cloud (ego vehicle will be missing because it is not part of the RGB-D images)
Reference image (taken with same FOV (80 degree), resolution, and extrinsic parameters)
I am very certain that there is no issue with the extrinsic matrix calculation and the reprojection part because it is well tested and verified. The zoom in effect comes from the intrinsic matrix.
I am assuming that I am missing or doing something wrong while calculating fx and fy. Perhaps, there may be a need of adjustment factor while dealing with different FOV's or some inconsistencies in the units.
Any help here would be appreciated.

Gnoplot: Plotting polar density

I have numerical wavefunction in radial (r-coordinate) and have to add spherical harmonics with theta [i.e, psi(r, theta)=R(r)*Y(theta)]. r values lie range [0, 4] with 0.01 step corresponding 400 points. What should be theta step at range [0, 360]?
To get a polar density, How to design .dat file?

How to get camera calibration matrices?

I am currently experimenting with ORB SLAM 2 and a stereo camera like this. I am using 2.8mm and optionally 3.6mm lenses with a resolution of 640x480 pixels for the left and right camera/image.
ORB SLAM 2 lets me define several distortion/rectifying parameters withing the settings file (*.yaml), such as:
fx, fy, cx, cy
k1, k2, p1, p2
I conducted the OpenCV camera calibration using a chessboard like described here (9x7 inner corners and 70mm square length). Later on I used this automated calibration program from MRPT which gives me the same results with less stumbling blocks.
However, ORB SLAM 2 lets me define these additional parameters for pre-rectifying the images (if I understand this correctly):
D: 1x5 Matrix -> Distortion Coefficients aquired from calibration (fx,fy,cx,cy) ?
K: 3x3 Matrix -> Intrinsic Matrix aquired from calibration (k1,k2,p1,p2,k3) ?
R: 3x3 Matrix -> Rectification Transformation ?
P: 3x4 Matrix -> New Projection Matrix ?
My questions are the following (see below for an example settings.yaml file):
A.) Is my assumption correct, that D are the distortion coefficients and K is the intrinsic matrix acquired from the checkboard calibration procedure ?
B.) Is defining fx, fy, cx, cy in settings.yaml sufficient for pre-rectifying the images and successful operation of ORB SLAM 2 ?
C.) Do I need R and P matrices for successful operation of ORB SLAM 2 ?
D.) How can I acquired the R and P matrices? The OpenCV camera calibration procedure with the checkboard does not provide me these matrices, correct ?
Here's an example of the above mentioned settings.yaml file of ORB SLAM 2:
%YAML:1.0
#--------------------------------------------------------------------------------------------
# Camera Parameters. Adjust them!
#--------------------------------------------------------------------------------------------
# Camera calibration and distortion parameters (OpenCV)
Camera.fx: 646.53807309613160
Camera.fy: 647.36136487241527
Camera.cx: 320.94123353073792
Camera.cy: 219.07092188981900
Camera.k1: -0.43338537102343577
Camera.k2: 0.46801812273859494
Camera.p1: 0.0039978632628183738
Camera.p2: 0.00023265675941025371
Camera.width: 640
Camera.height: 480
# Camera frames per second
Camera.fps: 20.0
# stereo baseline times fx
Camera.bf: 38.76
# Color order of the images (0: BGR, 1: RGB. It is ignored if images are grayscale)
Camera.RGB: 1
# Close/Far threshold. Baseline times.
ThDepth: 50
#--------------------------------------------------------------------------------------------
# Stereo Rectification. Only if you need to pre-rectify the images.
# Camera.fx, .fy, etc must be the same as in LEFT.P
#--------------------------------------------------------------------------------------------
LEFT.width: 640
LEFT.height: 480
LEFT.D: !!opencv-matrix
rows: 1
cols: 5
dt: d
data:[-0.28340811, 0.07395907, 0.00019359, 1.76187114e-05, 0.0]
LEFT.K: !!opencv-matrix
rows: 3
cols: 3
dt: d
data: [458.654, 0.0, 367.215, 0.0, 457.296, 248.375, 0.0, 0.0, 1.0]
LEFT.R: !!opencv-matrix
rows: 3
cols: 3
dt: d
data: [0.999966347530033, -0.001422739138722922, 0.008079580483432283, 0.001365741834644127, 0.9999741760894847, 0.007055629199258132, -0.008089410156878961, -0.007044357138835809, 0.9999424675829176]
LEFT.P: !!opencv-matrix
rows: 3
cols: 4
dt: d
data: [435.2046959714599, 0, 367.4517211914062, 0, 0, 435.2046959714599, 252.2008514404297, 0, 0, 0, 1, 0]
RIGHT.width: 640
RIGHT.height: 480
RIGHT.D: !!opencv-matrix
rows: 1
cols: 5
dt: d
data:[-0.28368365, 0.07451284, -0.00010473, -3.555907e-05, 0.0]
RIGHT.K: !!opencv-matrix
rows: 3
cols: 3
dt: d
data: [457.587, 0.0, 379.999, 0.0, 456.134, 255.238, 0.0, 0.0, 1]
RIGHT.R: !!opencv-matrix
rows: 3
cols: 3
dt: d
data: [0.9999633526194376, -0.003625811871560086, 0.007755443660172947, 0.003680398547259526, 0.9999684752771629, -0.007035845251224894, -0.007729688520722713, 0.007064130529506649, 0.999945173484644]
RIGHT.P: !!opencv-matrix
rows: 3
cols: 4
dt: d
data: [435.2046959714599, 0, 367.4517211914062, -47.90639384423901, 0, 435.2046959714599, 252.2008514404297, 0, 0, 0, 1, 0]
#--------------------------------------------------------------------------------------------
# ORB Parameters
#--------------------------------------------------------------------------------------------
# ORB Extractor: Number of features per image
ORBextractor.nFeatures: 800
# ORB Extractor: Scale factor between levels in the scale pyramid
ORBextractor.scaleFactor: 1.2
# ORB Extractor: Number of levels in the scale pyramid
ORBextractor.nLevels: 8
# ORB Extractor: Fast threshold
# Image is divided in a grid. At each cell FAST are extracted imposing a minimum response.
# Firstly we impose iniThFAST. If no corners are detected we impose a lower value minThFAST
# You can lower these values if your images have low contrast
ORBextractor.iniThFAST: 12
ORBextractor.minThFAST: 3
#--------------------------------------------------------------------------------------------
# Viewer Parameters
#--------------------------------------------------------------------------------------------
Viewer.KeyFrameSize: 0.05
Viewer.KeyFrameLineWidth: 1
Viewer.GraphLineWidth: 0.9
Viewer.PointSize:2
Viewer.CameraSize: 0.08
Viewer.CameraLineWidth: 3
Viewer.ViewpointX: 0
Viewer.ViewpointY: -0.7
Viewer.ViewpointZ: -1.8
Viewer.ViewpointF: 500
In my opinion, there are several calibration toolboxes used for calibrating monocular, stereo or multi-cameras.
The first one is ros_camera_calibration. when running ORBSLAM, I prefer to use this package to obtain the intrinsic parameters of the single moving camera. The intrinsic parameters and distortion coefficients, and projection matrices would be acquired after moving the calibration board.
the second one, what I recently used is Kalibr. It is not only designed to calibrate multi-cameras but also can calibrate jointly the camera and inertial measurement units(IMU).
Besides, You also can use MATLABto get the camera's intrinsic parameters.
As for your questions, here are my imperfect answers.
Q.A: K(fx, fy, cx,cy) stands for the intrinsic parameters of the camera and distortion Coefficients are k1,k2,p1.p2 separately.
Q.B: as far as I'm concerned, obtaining intrinsic parameters, including fx, fy, cx, cy, are sufficient to run ORBSLAM2 with your own cameras.
Q.C&D, if you choose to use this ROS package, in the end, you will receive the projection matrix and rectification transformation.

Point coordinates at given distance on UIBezierPath

I have a UIBezierPath line and I would like to get the coordinates of a point that is on this line at a given distance of the beginning of this line. By distance I mean distance ALONG the line.
On the following picture, I am looking for x and y.
The perfect solution would be a method that takes the distance as an argument and return the coordinates.
CGPoint myPoint = [myLine pointAtdistance:53.21]
Does something similar exist ? I thought it would be a common problem, but was not able to find any relevant info on the web. Maybe I am searching for the wrong thing ?
Thank you.
If path contains no curve segments, only linear ones, and there is a lot of distance requests for one path, then you can use some preprocessing (1st item):
1. Calculate length of every segment, and cumulative path length till this segment's end
2. With distance request, find proper segment by binary search
(or linear search, if the number of segments is small)
3. Find parameter (0..1) of relative position of point in this segment
4. Calculate coordinates as linear combination of segment end points.
Simple example:
Points (0,0), (1,0), (1,2), (4,-2), (6,-2)
Lengths [1, 2, 5, 2]
Path cumul. lengths: [0, 1, 3, 8, 10]
Distance req.: 5
Binary search finds 3rd segment (5 is between 3 and 8)
3*(1-t)+8*t=5 (equation to find a parameter)
t = 0.4
X = P[2].X * (1-t) + P[3].X * t
Y = P[2].Y * (1-t) + P[3].Y * t
use (1,2) and (4,-2) coordinates
(X,Y)= (2.2, 0.4)

Performing shear with altered origin in OpenCV

I want to shear an image along the y-axis, but keeping a given x value in the same height.
If I use a shear matrix as:
[1, 0, 0]
[s, 1, 0]
with s = the shear factor with the function "warpAffine", I do get my sheared image, but it's always with origin at 0,0.
I need to have my origin at another x (and maybe even y).
So I think I should combine translation matrices, to translate the image to the left, perform the shear and translate the image back to the right, but I am unsure how to combine these matrices, since:
[1, 0, dx] [1, 0, 0] [1, 0, -dx]
[0, 1, dy] * [s, 1, 0] * [0, 1, -dy]
obviously won't work.
How can I perform a shearing operation on a chosen origin other than 0,0?
you are correct that you should combine those transforms. To combine them convert all of them to 3x3 matrices by adding [0,0,1] as the 3rd row. Then you can multiply all 3 matrices. When you finish the bottom row will still be [0,0,1], you can then remove it and use the resulting 2x3 matrix as your combined transform.

Resources