Thursday, 2 July 2015

OpenCV findCirclesGrid with color filter

1. Convert RGB image to HSV for better colour identification.
As a side note, in OpenCV H has values from 0 to 180, S and V from 0 to 255. The red color, in OpenCV, has the hue values approximately in the range of 0 to 10 and 160 to 180.
In HSV space:
red primary at 0°
green primary at 120° (60 - opencv)
blue primary at 240° (120 - opencv)
yellow (30 - opencv)


// Convert input image to HSV
cv::Mat hsv_image;
cv::cvtColor(bgr_image, hsv_image, cv::COLOR_BGR2HSV);

2. Use cv::inRange function to filter out colour
// Threshold the HSV image, keep only the red pixels
cv::Mat lower_red_hue_range;
cv::Mat upper_red_hue_range;
cv::inRange(hsv_image, cv::Scalar(0, 100, 100), cv::Scalar(10, 255, 255), lower_red_hue_range);
cv::inRange(hsv_image, cv::Scalar(160, 100, 100), cv::Scalar(179, 255, 255), upper_red_hue_range);

3. Use cv::addWeighted function to filter out colour
cv::Mat red_hue_image;
cv::addWeighted(lower_red_hue_range, 1.0, upper_red_hue_range, 1.0, 0.0, red_hue_image);


Reference:
[1] Detect red circles in an image using OpenCV


Thursday, 4 June 2015

Argon Plasma Coagulation (APC) laparoscopy application


1. Use of Neutral Argon Plasma in the Laparoscopic Treatment of Endometriosis: link
Neutral argon plasma can be utilized as a multi-functional device that has vaporization, coagulation, and superficial cutting capacities with minimal thermal spread and acceptable outcomes. The use of neutral argon plasma appears to be efficacious and safe for the complete treatment of endometriotic implants.

Vaporization: the probe was directed at the lesions from a distance of close to 5mm, spraying the tissue surface at an angle of approximately 45 degrees until the tissue surface demonstrated a characteristic silver, shiny appearance and there was visual confirmation of complete eradication of the lesions
Cutting: closer to the tissue surface at approximately a 90-degree angle

Within the limitations of a pilot study, plasma energy appears to be efficacious and safe for the complete vaporization of endometriotic implants and can be used for the laparoscopic management of endometriosis.

2. Barrett's Oesophagus: Long-term Follow-up After Complete Ablation With Argon Plasma Coagulation: link
laparoscopic fundoplication

3. Argon plasma coagulation for successful treatment of early gastric cancer with intramucosal invasion: link





hematischesis:



Saturday, 30 May 2015

Different ways to estimate relative pose during visual servoing

In order to obtain relative pose (pdHp) between current and desired pattern pose (cHp and cHpd) in camera frame, we can:

Method 1: Find rigid transformation between two set of pattern points (X_p and X_pd) in camera frame directly using a findRigidTransform() function described here.

Method 2: Calculate cHp and cHpd using the findRigidTransform() as the pattern points in local coordinate is known. The relative pose pdHp is calculated as:
pdHp = inv(cHpd) * cHp

Method 3: Calculate cHp and cHpd using the cv::solvePnP() function which finds an object pose from 3D-2D point correspondence. The relative pose is then calculated same as method 2.

According to the results, Method 1 is least stable and accurate as the estimated relative pose varies a lot and very different from the other two methods.
Method 2 and 3 have similar results in which Method 3 seems better since the rotation part is closer to Identity when the relative pose should be the same.

Summary: Method 3 is the best for the time being.

Thursday, 28 May 2015

Relative trajectory playback from different starting pose

1. Given a trajectory in the global frame, a relative trajectory (H_rela) can be generated as:
H_rela = inv(H_1) * H_i
Since the relative transformation is regard to local frame (first pose in the trajectory). H_rela(1) is Identity

2. For a new starting pose in the global frame H_start, a new trajectory begins at the starting pose is generated as:

H_new = H_start * H_rela
where H_new is in the global frame.

Tuesday, 5 May 2015

Git - update submodule

Update and merge/rebase local submodule with upstream:

git submodule update --remote --merge
git submodule update --remote --rebase

Under main project directory, see difference of submodule:
git diff --submodule


3 cases:
  • Same commit but submodule has dirty suffix
-Subproject commit c5c6bbaf616d64fbd873df7b7feecebb81b5aee7
+Subproject commit c5c6bbaf616d64fbd873df7b7feecebb81b5aee7-dirty

It means that git status in the submodule isn't clean. cd into the submodule and see what's going on.

  • Different commit, former one is correct (the one in main project)
-Subproject commit c4478af032e604bed605e82d04a248d75fa513f7
+Subproject commit c79d9c83c2864665ca3fd0b11e20a53716d0cbb0
If the former is right, add and commit the new version of the submodule in main project
  • Different commit, latter one is correct (the one in submodule)
If the latter is right, change the version that the submodule is at with:
git submodule update $submodule_name$






Reference:
[1] http://git-scm.com/book/en/v2/Git-Tools-Submodules
[2] http://stackoverflow.com/questions/6006494/git-submodule-modified-files-status

Monday, 23 March 2015

Angular velocity and Skew Symmetric Matrices

A matrix S is said to be skew symmetric if and only if: S^T + S = 0.
Thus S contains only three independent entries and every 3 × 3 skew symmetric matrix has the form:


If a = (a_x, a_y, a_z)' is a 3-vector, the skew symmetric matrix S(a) can be defined as:

Important properties of the matrix S(a):
  • Linearity: for any vector a and b belonging to R^3 and scalars alpha and beta:
    • S(alpha*a + beta*b) = alpha*S(a) + beta*S(b)
  • Calculation of cross project: for any vector p = (p_x, p_y, p_z)':
    • S(a)*p = a.cross(p)
  • For an orthogonal matrix (such as rotation) R in SO(3), and a,b are vector in R^3:
    • R(a.cross(b)) = (R*a).cross(R*b)
  • For R in SO(3) and a vector a belongs to R^3, we have:
    • the deviation is:





  • Computing the derivative of the rotation matrix R is equivalent to a matrix multiplication by a skew symmetric matrix S, that is:

Velocity of a point on a rotating rigid body which is moving with a linear velocity is derived in: