<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Minghao Ning on Medium]]></title>
        <description><![CDATA[Stories by Minghao Ning on Medium]]></description>
        <link>https://medium.com/@MinghaoNing?source=rss-5b4ecb9c2828------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ehicOmW0F5A69rYiHO8x2Q@2x.jpeg</url>
            <title>Stories by Minghao Ning on Medium</title>
            <link>https://medium.com/@MinghaoNing?source=rss-5b4ecb9c2828------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 22:03:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@MinghaoNing/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[JetsonSetupGuide]]></title>
            <link>https://medium.com/@MinghaoNing/jetsonsetupguide-a7993026f219?source=rss-5b4ecb9c2828------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7993026f219</guid>
            <category><![CDATA[autonomous-cars]]></category>
            <category><![CDATA[jetpack]]></category>
            <category><![CDATA[robotics]]></category>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Minghao Ning]]></dc:creator>
            <pubDate>Fri, 15 Nov 2024 05:31:41 GMT</pubDate>
            <atom:updated>2024-11-15T05:31:41.880Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://github.com/NingMingHao/Yolov8TensorrtRos/blob/main/data/JetsonOrinTestVideo.gif">Yolov8TensorrtRos/data/JetsonOrinTestVideo.gif at main · NingMingHao/Yolov8TensorrtRos</a></p><figure><img alt="A real-time detection containing 3 Lidars and 6 cameras using only ONE Jetson." src="https://cdn-images-1.medium.com/max/1024/1*Q8oqzskDbUdQ4_H7k33Zig.png" /><figcaption>A real-time detection containing 3 Lidars and 6 cameras using only ONE Jetson.</figcaption></figure><p>Setting up NVIDIA Jetson devices for optimal performance in robotics and computer vision applications can be intricate. To streamline this process, the <a href="https://github.com/NingMingHao/JetsonSetupGuide">JetsonSetupGuide</a> repository offers comprehensive scripts and instructions for installing ROS, OpenCV with CUDA support, and other essential packages on Jetson platforms.</p><p><strong>Repository Overview</strong></p><p>The JetsonSetupGuide repository provides:</p><ul><li><strong>ROS Installation</strong>: Scripts to install the Robot Operating System (ROS) on Jetson devices, facilitating robotics development.</li><li><strong>OpenCV with CUDA Support</strong>: Instructions to build and install OpenCV optimized with CUDA, enhancing computer vision tasks.</li><li><strong>Additional ROS Packages</strong>: Guidance on installing ROS packages that depend on OpenCV.</li><li><strong>NVMe SSD Cloning (Optional)</strong>: Steps to clone the Jetson’s NVMe SSD for backup or replication purposes.</li></ul><p><strong>Supported Devices and Software Versions</strong></p><p>The guide has been tested on:</p><ul><li><strong>Devices</strong>: Jetson AGX Orin and Jetson AGX Orin NX.</li><li><strong>Software</strong>: JetPack 5.1.2, ROS Noetic, and OpenCV 4.5.5.</li></ul><p><strong>Prerequisites</strong></p><p>Before proceeding, ensure JetPack is installed on your Jetson device. If not, follow the official instructions to install JetPack using the SDK Manager.</p><p><strong>Setup Instructions</strong></p><ol><li><strong>Clone the Repository </strong>to your Jetson device:</li></ol><pre>git clone https://github.com/NingMingHao/JetsonSetupGuide.git</pre><p><strong>2. Modify Configuration Variables</strong></p><p>Navigate to the docs directory and edit the following scripts to match your system&#39;s configuration:</p><ul><li>install_ros.sh</li><li>install_opencv.sh</li><li>install_packages.sh</li></ul><p>Update the variables:</p><ul><li>HOME_USER: Your username.</li><li>OPENCV_VERSION: Desired OpenCV version.</li><li>CUDA_ARCH_BIN: CUDA architecture version for your GPU. Refer to <a href="https://developer.nvidia.com/cuda-gpus">NVIDIA&#39;s CUDA documentation</a> to determine the correct CUDA_ARCH_BIN for your device.</li><li>ROS_VERSION: Desired ROS version.</li></ul><p><strong>3. Run the Installation Scripts</strong></p><p>Execute the scripts in the following order:</p><ul><li><strong>Install ROS</strong>:</li></ul><pre>cd docs<br>sudo -s<br>bash install_ros.sh</pre><ul><li><strong>Install OpenCV with CUDA Support</strong>:</li></ul><pre>bash install_opencv.sh</pre><ul><li><strong>Install Additional ROS Packages</strong>:</li></ul><pre>bash install_packages.sh</pre><p>These scripts will automate the installation and configuration of ROS, OpenCV with CUDA support, and other necessary packages.</p><p><strong>Optional: Cloning the Jetson NVMe SSD</strong></p><p>For users interested in cloning the Jetson’s NVMe SSD, the repository provides guidance on this process. Cloning can be useful for creating backups or replicating setups across multiple devices.</p><p><strong>Conclusion</strong></p><p>The JetsonSetupGuide repository simplifies the setup of NVIDIA Jetson devices for robotics and computer vision applications. By following the provided scripts and instructions, developers can efficiently configure their Jetson platforms with ROS, OpenCV optimized with CUDA, and other essential tools.</p><p>For detailed instructions and the latest updates, visit the <a href="https://github.com/NingMingHao/JetsonSetupGuide">JetsonSetupGuide GitHub repository</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7993026f219" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Set Up VMware, Ubuntu 22, ROS2, and Gazebo on Arm64 (like Apple Silicon or Jetson)]]></title>
            <link>https://medium.com/@MinghaoNing/how-to-set-up-vmware-ubuntu-22-ros2-and-gazebo-on-arm64-like-apple-silicon-or-jetson-5bb4db6ff297?source=rss-5b4ecb9c2828------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bb4db6ff297</guid>
            <category><![CDATA[gazebo]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[ros2]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[autonomous-cars]]></category>
            <dc:creator><![CDATA[Minghao Ning]]></dc:creator>
            <pubDate>Thu, 05 Sep 2024 05:43:44 GMT</pubDate>
            <atom:updated>2025-01-27T22:45:27.683Z</atom:updated>
            <content:encoded><![CDATA[<p>In this guide, I’ll walk you through the process of setting up a virtual machine using VMware Fusion on an Arm64 devices (Like Apple Silicon or Nvidia Jetsons). We will install <strong>Ubuntu 22</strong>, configure it for ROS2, and manually install <strong>Gazebo</strong>, the popular robotics simulation platform. This process is particularly relevant for those who are working with ARM64 architecture, such as the Apple M1/M2 chips, where support for certain platforms is not readily available.</p><h3><strong>Why This Setup?</strong></h3><p>Apple’s M1 and M2 chips bring significant processing power, but they run on ARM64 architecture, which can present challenges when installing software traditionally built for x86 systems. Specifically, installing and running Gazebo for robotics simulations requires a manual setup due to its lack of direct support for ARM64.</p><h3><strong>Step 1: Install VMware Fusion</strong></h3><p>The first step is to download and install VMware Fusion. VMware Fusion allows you to run a virtual machine on your Mac, making it possible to install and run Ubuntu.</p><p><strong>Download VMware Fusion</strong></p><p>You should first register an account like: <a href="https://profile.broadcom.com/web/registration">https://profile.broadcom.com/web/registration</a></p><p>Then download VMware Fusion 13.6 from the following link: <a href="https://support.broadcom.com/group/ecx/productfiles?subFamily=VMware%20Fusion&amp;displayGroup=VMware%20Fusion%2013%20Pro%20for%20Personal%20Use&amp;release=13.6&amp;os=&amp;servicePk=522387&amp;language=EN">https://support.broadcom.com/group/ecx/productfiles?subFamily=VMware%20Fusion&amp;displayGroup=VMware%20Fusion%2013%20Pro%20for%20Personal%20Use&amp;release=13.6&amp;os=&amp;servicePk=522387&amp;language=EN</a></p><h3><strong>Step 2: Install Ubuntu 22 ARM64</strong></h3><p>Download the ubuntu22 iso image:</p><p><a href="https://rhlx01.hs-esslingen.de/Mirrors/cdimage.ubuntu.com/jammy/daily-live/manual/jammy-desktop-arm64.iso">https://rhlx01.hs-esslingen.de/Mirrors/cdimage.ubuntu.com/jammy/daily-live/manual/jammy-desktop-arm64.iso</a></p><p><strong>Install Ubuntu on VMware Fusion</strong></p><p>1. Open VMware Fusion and select <strong>Create a New Virtual Machine</strong>.</p><p>2. Drag the downloaded jammy-desktop-arm64.iso file into the virtual machine setup window.</p><p>3. Follow the prompts and select <strong>Erase Disk and Install Ubuntu</strong>.</p><p>4. Once installation is complete, click “Restart Now” and then press “Enter” when it shows “remove installation medium”.</p><h3>Step 3: <strong>Configure Ubuntu for VMware</strong></h3><p>To enhance the experience, you’ll want to ensure that Ubuntu works smoothly within VMware. After installation, follow these steps:</p><ol><li>Open a terminal and run the following command to install VMware tools, and then the clipboard will share across the virtual machine and the MacOS:</li></ol><pre>sudo apt-get install open-vm-tools-desktop</pre><p>2. Power off the Ubuntu virtual machine, and adjust the hardware settings in VMware:<br>a. Increase the number of processors and memory. I assigned 6 cores and 8192MB for my 16GB m2 pro.<br>b. Go to “Display” and make sure “Accelerate 3D graphics” is <strong>not enabled</strong>.<br>c. Increase the disk space, click “Hard Disk NVMe”, increase it to 30GB.<br>d. Then turn on the ubuntu22.<br>e. Open “Disks”, and <strong>resize</strong> the partition ending with Ext4.</p><h3>Step 4: <strong>Install ROS2</strong></h3><p>Now that Ubuntu is configured, the next step is to install ROS2. Follow the repository guide <a href="https://github.com/UW-MTE544/MTE544_student/tree/setup">here</a> for detailed steps.</p><p>If you don’t have git installed, you can install it by running:</p><pre>sudo apt install git</pre><h3>Step 5: <strong>Install Gazebo on ARM64</strong></h3><p><a href="https://github.com/gazebosim/gazebo-classic">Gazebo</a>, the simulation platform, doesn’t directly support ARM64 architecture. As a result, we need to manually compile and install it.</p><ol><li>Install necessary dependencies:</li></ol><pre>sudo apt-add-repository ppa:dartsim<br>sudo apt update<br>sudo apt install libdart-dev libdart-utils-dev libdart-external-ikfast-dev libsdformat9-dev libfreeimage-dev libprotoc-dev libprotobuf-dev protobuf-compiler freeglut3-dev libcurl4-openssl-dev libtinyxml-dev libtinyxml2-dev libtar-dev libtbb-dev libogre-1.9-dev libxml2-dev pkg-config qtbase5-dev libqwt-qt5-dev libltdl-dev libgts-dev libboost-thread-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-regex-dev libboost-iostreams-dev libsimbody-dev libignition-common3-dev libignition-fuel-tools4-dev libignition-transport8-dev libignition-math6-dev libignition-msgs5-dev</pre><p>2. Clone the Gazebo source code from GitHub:</p><pre>cd ~/Downloads/<br>git clone https://github.com/osrf/gazebo</pre><p>3. Modify the line 647 of SearchForStuff.cmake in Downloads/gazebo/cmake. Change from 9.8 to 9.7 as the default libsdformat version of ubuntu22 is 9.7.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w4c5jfVFLdugQ0iioHgBrw.png" /></figure><p>4. Compile and install Gazebo:</p><pre>cd ~/Downloads/gazebo<br>mkdir build &amp;&amp; cd build<br>cmake ../<br>make -j3<br>sudo make install</pre><p>5. Add Gazebo to your environment path by modifying .bashrc:</p><pre>export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH<br>export PATH=/usr/local/bin:$PATH<br>export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH</pre><h3>Step 6: <strong>Compile TurtleBot3 Packages</strong></h3><ol><li>Create a workspace for the packages:</li></ol><pre>cd ~/Downloads<br>mkdir turtlebot_gazebo_ws &amp;&amp; cd turtlebot_gazebo_ws<br>mkdir src &amp;&amp; cd src</pre><p>2. Clone the turtlebot3_simulations</p><pre>cd ~/Downloads/turtlebot_gazebo_ws/src<br>git clone https://github.com/ROBOTIS-GIT/turtlebot3_simulations<br>cd turtlebot3_simulations<br>git checkout humble</pre><p>3. Clone the gazebo_ros_pkgs</p><pre>cd ~/Downloads/turtlebot_gazebo_ws/src<br>git clone https://github.com/ros-simulation/gazebo_ros_pkgs<br>cd gazebo_ros_pkgs<br>git checkout ros2</pre><p>4. Clone the turtlebot4 pkgs</p><pre>cd ~/Downloads/turtlebot_gazebo_ws/src<br>git clone https://github.com/turtlebot/turtlebot4<br>cd turtlebot4<br>git checkout humble</pre><p>5. Compile the workspace</p><pre>sudo apt-get install ros-humble-camera-info-manager ros-humble-irobot-create-msgs<br>cd ~/Downloads/turtlebot_gazebo_ws<br>export MAKEFLAGS=&quot;-j 3&quot;<br>colcon build</pre><p>6. Add the following line to the end of .bashrc file</p><pre>source ~/Downloads/turtlebot_gazebo_ws/install/setup.bash</pre><h3>Test the installation</h3><pre>ros2 launch turtlebot3_gazebo turtlebot3_house.launch.py<br>ros2 launch turtlebot4_navigation slam.launch.py<br>ros2 launch turtlebot4_viz view_robot.launch.py <br>ros2 run teleop_twist_keyboard teleop_twist_keyboard</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w4GjymlRENH8PRgpMZ5Jog.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bb4db6ff297" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SIFT(Scale-invariant feature transform)]]></title>
            <link>https://medium.com/data-science/sift-scale-invariant-feature-transform-c7233dc60f37?source=rss-5b4ecb9c2828------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7233dc60f37</guid>
            <category><![CDATA[sift]]></category>
            <category><![CDATA[feature-description]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[feature-detection]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Minghao Ning]]></dc:creator>
            <pubDate>Tue, 09 Apr 2019 08:18:57 GMT</pubDate>
            <atom:updated>2019-04-10T02:11:38.897Z</atom:updated>
            <content:encoded><![CDATA[<h4>In this article, I will give a detailed explanation of the SIFT algorithm and its mathematical principles.</h4><p>I hope you will understand these after your reading🤔:</p><ol><li>The main steps of SIFT</li><li>Why we need to multiply the LoG by σ² to get the scale invariance</li><li>Appromixing LoG using DoG</li><li>why we use Hessian to reject some features located on edges.</li></ol><p>SIFT is proposed by <strong>David G. Lowe</strong> in his <a href="https://people.eecs.berkeley.edu/~malik/cs294/lowe-ijcv04.pdf">paper</a>. ( This paper is easy to understand, I recommend you to have a look at it ).</p><p>In general, SIFT algorithm can be decomposed into four steps:</p><ol><li>Feature point (also called keypoint) detection</li><li>Feature point localization</li><li>Orientation assignment</li><li>Feature descriptor generation.</li></ol><p>And this article will also follow these steps.</p><h3>Feature point detection</h3><p>As its name shows, SIFT has the property of <strong><em>scale invariance</em></strong>, which makes it better than <a href="https://en.wikipedia.org/wiki/Harris_Corner_Detector">Harris</a>. Harris is not scale-invariant, a <strong><em>corner</em></strong> may become an <strong><em>edge</em></strong> if the scale changes, as shown in the following image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/1*Me5AIiIrG3lJwEo1YBn26w.png" /><figcaption>Harris is not scale-invariant</figcaption></figure><p>So what is scale, and what does scale invariance mean?<br>An excellent explanation is given in <a href="https://people.kth.se/~tony/papers/scsptheory-review.jas94.pdf">Tony Lindeberg’s paper</a>:</p><blockquote><em>An inherent property of objects in the world is that they only exist as meaningful entities over certain ranges of scale. A simple example is the concept of a branch of a tree, which makes sense only at a scale from, say, a few centimeters to at most a few meters. It is meaningless to discuss the tree concept at the nanometer or the kilometer level. At those scales it is more relevant to talk about the molecules that form the leaves of the tree, or the forest in which the tree grows. Similarly, it is only meaningful to talk about a cloud over a certain range of coarse scales. At finer scales it is more appropriate to consider the individual droplets, which in turn consist of water molecules, which consist of atoms, which consist of protons and electrons etc.</em></blockquote><p>The scale of an image landmark is its (rough) diameter in the image. It is denoted by σ, which is measured in pixels, you can think scale invariance as that we can detect similar landmarks even if their scale is different.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*jkXSTo71vLQobIAC_s89rQ.png" /></figure><p>So how does SIFT achieves scale invariance?<br>Do you still remember the <strong><em>pyramids</em></strong>?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*cJF_YgCOMjhZDJQinfojTA.png" /></figure><p>We can find the features under various image sizes.<br>Besides, we can also use the Laplacian of Gaussian(LoG) with different σ to achieve this.</p><p>Let’s first have a look at LoG.<br>As <a href="https://medium.com/lis-computer-vision-blogs/scale-invariant-feature-transform-sift-detector-and-descriptor-14165624a11">Li Yin’s article</a> indicates, the LoG operation goes like this. You take an image, and blur it a little (using Gaussian kernel). And then, you calculate the sum of second-order derivatives on it (or, the “Laplacian”). This locates edges and corners on the image. These edges and corners are good for finding keypoints (note that we want a key<strong>point</strong> detector, which means we will do some extra operations to suppress the edge). LoG is often used for <strong><em>blob detection</em></strong> (I will explain it later).<br>Remember the relationship between convolution and differentiation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/258/1*zQRh1ysOQ-h3xerWgEMAsg.png" /></figure><p>We can just convolve the image with <strong><em>the second derivatives of Gaussian, and sum them</em></strong> (or just convolve using LoG).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*_GLMkdxuGZOq4BrYvXbj3A.png" /></figure><p>Take a 1-D example, <strong><em>f</em></strong> is a scanline of an image (i.e. the pixel array from a line of an image).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*wSXq25SQXJ6dGguZ2iCe3Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*gQFZrQeqn2ZHj1DMhhnHSA.png" /></figure><p>You can see that if we use LoG to detect the edge, we need to find the zero crossing the LoG response. Instead of finding the zero crossing, we can use LoG to detect the <strong><em>blob</em></strong> as we said above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*Li6T7E-NB4CrcamoadfqUQ.png" /></figure><p>Aha! We don’t need to find the zero crossing anymore, we can find the extrema (maxima and minima) instead.<br>However, the LoG is not <strong><em>truly</em></strong> scale invariant, you can find that: Laplacian response decays as scale increases:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*7eIi6OB6XYuXXKrBJvZ0fg.png" /></figure><p>So why does this happen?</p><p>I will give you two ways to explain that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*7FQKZ6au20qO2pFm3Ej31Q.png" /></figure><ul><li>The response of a derivative of Gaussian filter to a perfect step edge decreases as σ increases.</li><li>To keep response the same(scale-invariant), must multiply Gaussian derivative by σ.</li><li>Laplacian is the second Gaussian derivative, so it must be multiplied by σ2.</li></ul><p><strong>If you are satisfied with the above explanation and you are tired of struggling with some mathematical concepts, feel free to skip the following explanation.</strong></p><p>Another explanation is from <a href="http://www.cim.mcgill.ca/~langer/558/2009/lecture11.pdf">this tutorial pdf</a>.</p><p>Consider a noise-free image edge I(x) = u(x − x0), u is the <strong><em>unit step function</em></strong>. To detect edges previously, we convolved them with a derivative of Gaussian and then looked for a peak in the response. Suppose we define a scale space by convolving I(x) with a family of the first derivative of Gaussian filters, where <strong><em>a family</em></strong> means we have a family of σ.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*vxjIhGISK9kP09TzqyW4Xg.png" /></figure><p>At the location of the edge x = x0, we have</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*X6WKRIe9k0EeTwvIXTmAog.png" /></figure><p>which depends on σ.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*8gij7B5jg6sAS_7VNerUPg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/96/1*8rE5TyezLa7TZgBPF8KVZw.png" /></figure><p>If we have a 2D image, then we define the normalized derivative filter in the same way, namely</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/96/1*8rE5TyezLa7TZgBPF8KVZw.png" /></figure><p>and similarly for y. Exactly the same arguments as above are used to show that the<br>value at a horizontal or vertical edge will be independent of σ. Using these filters, one defines the normalized gradient scale space in the obvious way, and one will find that the gradient at an edge of arbitrary orientation will be independent of σ.<br><strong>Now here comes the second derivates</strong><br>We know that if we filter a (noise-free) edge, I(x) = u(x − x0), with the first derivative of a Gaussian then we get a peak response at the location of the edge. It follows immediately that if we were to filter the edge with the second derivative of a Gaussian</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/175/1*sC6kwocmgMASTONYd3hGYw.png" /></figure><p>then the response would be zero at the location of the edge.<br>The second derivative of a Gaussian filter, and its 2D equivalent, have been very important in computer vision as well as in human vision modeling, and was the basis for an influential early theory of edge detection. The response of this filter to the edge image is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*XE9s25v_B57ypghR83cIyQ.png" /></figure><p>and note that the response is indeed 0 when x = x0, as we expect.<br>Where do the peaks occur? Taking the derivative we get</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*K7N4Z17EGguQcAVh9w1N3w.png" /></figure><p>and set it to 0. The peak thus occurs when</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/182/1*EFzAA0jtinWFa8I1tGcntw.png" /></figure><p>that is, x=x0±σ. Substituting, we see that the value of the peak is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/100/1*63OrQqcRcC7gIsSM0FOPMg.png" /></figure><p>As we did with the first derivative filter, we can normalize the second derivative filter by multiplying by σ2, so the normalized second derivative filter is defined.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/96/1*P6sOiEqIcMFkhy1iV10swg.png" /></figure><p>This cancels the σ^(−2) dependence in the height of the peaks. Thus we see that if we filter an edge with a normalized second derivative of a Gaussian (as defined above), then there is a zero-crossing at the location of the edge and there are peaks (positive and negative) at a distance ±σ away from the edge, but the height of the peaks doesn’t depend on σ.</p><p>In summary, we need to <strong><em>multiply the LoG with σ2</em></strong> to get the true scale invariance. Following is the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*ht0Wp28yWGMXd-Zwa7QL7A.png" /></figure><p>Now we can detect the landmark at appropriate scale, it’s really important because we need to describe this region in later steps, and we need to choose its surrounding region based on that scale, as shown in following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*7p5Q_MlzGa3cxfx212UVtA.png" /></figure><p>In practice, the Laplacian is approximated using a Difference of Gaussian (DoG).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*Xm-XVYSrFx-MK1a3DFaY7Q.png" /></figure><p>The relationship between <strong><em>DoG</em></strong> and <strong><em>σ2LoG</em></strong> can be understood from the heat diffusion equation (parameterized in terms of σ rather than the more usual t = σ2, you can see <a href="https://people.kth.se/~tony/papers/scsptheory-review.jas94.pdf">page 11</a> for more details:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/1*rbKWbvv82ysWaR1i8kScbA.png" /></figure><p>From this, we see that LoG can be computed from the finite difference approximation to ∂G/∂σ, using the difference of nearby scales at kσ and σ:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*cAm1d-OIO1Xw1zDgk5WJCA.png" /></figure><p>and therefore:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*DrY9v9tD2KOs6drO6B1E3w.png" /></figure><p>This shows that when the DoG function has scales differing by a constant factor it already incorporates the σ2 scale normalization required for the scale-invariant Laplacian. The factor (k − 1) in the equation is a constant over all scales and therefore does not influence extrema location.</p><p>Above all, SIFT combines the pyramids and different σ-space to detect blobs under different scales.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FgIvcdMirRCZr80IxDjEVg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*qjWuosImhajfJLtlUy_IJA.png" /></figure><p>Note that the extrema are the maxima or minima around 3 dimensions (i.e. x,y,σ).</p><h3>Feature point localization (sub-pixel localization)</h3><p>This part is mainly from <a href="https://mi.eng.cam.ac.uk/~cipolla/lectures/PartIB/IB-SIFT-extra-material.pdf">N Campbell’s article</a>.<br>After step 1, we detect some key-points which are coarsely localized, at best to the nearest pixel, dependent upon where the features were found in the scale-space. They are also poorly localized in scale since σ is quantized into relatively few steps in the scale-space. The second stage in the SIFT algorithm refines the location of these feature points to sub-pixel accuracy whilst simultaneously removing any poor features. The sub-pixel localization proceeds by fitting a Taylor expansion to fit a 3D quadratic surface (in x,y, and σ) to the local area to interpolate the maxima or minima. Neglecting terms above the quadratic term, the expansion of the DoG is given in following where the derivatives are evaluated at the proposed point z0=[x0,y0,σ0]T and z=[δx,δy,δσ]T is the offset from this point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*3rV9rR6zVv--9Ytjlk5SgQ.png" /></figure><p>The location of the extremum zˆ is then determined by setting the derivative with respect to z equal to zeros:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*aWExM4vbrbSurEwI75EAxA.png" /></figure><p>The parameters may be estimated using standard difference approximations from neighbouring sample points in the DoG resulting in a 3 × 3 linear system which may be solved efficiently. The process may need to be performed iteratively since if any of the computed offset values move by more than half a pixel it becomes necessary to reevaluate z^ since the appropriate neighborhood for the approximation will have changed. Points which to not converge quickly are discarded as unstable.<br>The value at the localized extremum may be interpolated,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*aANtx7DuQMpUKHuilyp1qQ.png" /></figure><p>and any points with a value below a certain threshold rejected as low contrast points.<br>A final test is performed to remove any features located on edges in the image since these will suffer an ambiguity if used for matching purposes. A peak located on a ridge in the DoG (which corresponds to an edge in the image) will have a large principle curvature across the ridge and a low one along with it whereas <strong><em>a well-defined peak (blob) will have a large principle curvature in both directions</em></strong>. The Hessian <strong><em>H</em></strong> in x and y</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/230/1*EahxDbUkqoc2rQb99JQY2w.png" /></figure><p>is evaluated for the feature point, again using a local difference approximation, and the ratio of the eigenvalues λ1 and λ2, which correspond to the principal curvatures, compared to a threshold ratio r as in</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*A5qx-KQmxcBjE5-1rBDALw.png" /></figure><p>and high ratio points rejected.<br>This is a little similar to Harris, which cares about the derivate distribution of the region around the chosen point. (You can get more information from <a href="https://www.cse.psu.edu/~rtc12/CSE486/lecture06.pdf">this pdf</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*nThKXd9Qr2Jxq3dZwLShUA.png" /></figure><p>However, the eigenvalues of Hessian <strong><em>H</em></strong> correspond to the principal curvatures. So how?</p><p><a href="https://www.math.union.edu/~jaureguj/principal_curvatures.pdf">This pdf</a> gives an excellent explanation.<br>Let’s assume we have a surface M in R³ that is given by the graph of a smooth function z = f(x,y). Assume that M passes through the origin, p, and its tangent plane there is the {z = 0} plane (it’s almost true for the detected blob, think about the sunflowers). Let N = (0,0,1), a unit normal to M at p.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z7q3cJ8jOCbVBLLRB-ZLYQ.png" /></figure><p>Let v be a unit vector in TpM, say v = (v1,v2,0). Let c be the parameterized curve given by slicing M through the plane spanned by v and N:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IS_1ULKTO7JPX0WkkdUP2A.png" /></figure><p>That is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*p9afmn8I0ud_NWuOJ7YldA.png" /></figure><p>Now we can calculate the curvature of c along the v = (v1,v2,0) direction. κv is the reciprocal of the radius of the osculating circle to c at p.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*ZPSFA6BkT3BdC-Z9cu5F5g.png" /></figure><p>κv = c′′(t)|t=0<br>So,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*yVUOQN8rriQp4uIBbx1rnw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*QHvz7wAjlnm0O5GrcnpCuA.png" /></figure><p>The principal curvatures of the surface at p will be the largest and smallest possible values λ1,λ2 of κv (as v ranges over the possible unit tangent vectors). If you don’t understand this argument, you can have a look at the excellent <a href="https://towardsdatascience.com/a-one-stop-shop-for-principal-component-analysis-5582fb7e0a9c">blog about PCA</a>.</p><h3>Orientation Assignment</h3><p>Of course, we will use the Histogram of Oriented Gradient (HOG)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*s8cNVK68UNbA1ZEidg9wvQ.png" /></figure><p>An orientation histogram is formed from the gradient orientations of sample points within a region around the keypoint. The orientation histogram has 36 bins covering the 360-degree range of orientations. Each sample added to the histogram is weighted by its gradient magnitude and by a Gaussian-weighted circular window with a σ that is 1.5 times that of the scale of the keypoint.</p><h3>Feature descriptor generation</h3><p>The final stage of the SIFT algorithm is to generate the descriptor which consists of a normalized 128-dimensional vector. At this stage of the algorithm, we are provided with a list of feature points which are described in terms of location, scale, and orientation. This allows us to construct a local coordinate system around the feature point which should be similar across different views of the same feature.<br>The descriptor itself is a histogram formed from the gradient of the grayscale image. A 4×4 spatial grid of gradient angle histograms is used. The dimensions of the grid are dependent on the feature point scale and the grid is centered on the feature point and rotated to the orientation determined for the keypoint. Each of the spatial bins contains an angle histogram divided into 8. (128=4×4×8). The image gradient magnitude and angle are again generated from the scale-space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*3hcRuPZ8Uxbc3DoQ5c08mw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*Vdmv_By01vl6xYrgSxx8Lg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*prSUCVZEALrd5Apy7nO7FA.png" /></figure><p>The gradient angle at each pixel is then added to the corresponding angle bin in the appropriate spatial bin of the grid. The weight of each pixel is given by the magnitude of the gradient as well as a scale-dependent Gaussian (σ equal to one half the width of the descriptor window) centered on the feature point as shown as the blue circle. The purpose of this Gaussian window is to avoid sudden changes in the descriptor with small changes in the position of the window, and to give less emphasis to gradients that are far from the center of the descriptor, as these are most affected by misregistration errors.</p><p>During the histogram formation, trilinear interpolation is used to add each value, that is an interpolation in x, y and θ. This consists of interpolation of the weight of the pixel across the neighboring spatial bins based on distance to the bin centers as well as interpolation across the neighboring angle bins. The effect of the interpolation is demonstrated in the following figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qN1taU6irCVlECI5Ncqupg.png" /></figure><p>It is used to avoid all boundary effects in which the descriptor abruptly changes as a sample shifts smoothly from being within one histogram to another or from one orientation to another. Therefore, trilinear interpolation is used to distribute the value of each gradient sample into adjacent histogram bins. In other words, each entry into a bin is multiplied by a weight of 1 − d for each dimension, where d is the distance of the sample from the central value of the bin as measured in units of the histogram bin spacing.</p><blockquote><em>Finally, the feature vector is modified to reduce the effects of illumination change. First, the vector is normalized to unit length. A change in image contrast in which each pixel value is multiplied by a constant will multiply gradients by the same constant, so this contrast change will be canceled by vector normalization. A brightness change in which a constant is added to each image pixel will not affect the gradient values, as they are computed from pixel differences. Therefore, the descriptor is invariant to affine changes in illumination. However, non-linear illumination changes can also occur due to camera saturation or due to illumination changes that affect 3D surfaces with differing orientations by different amounts. These effects can cause a large change in relative magnitudes for some gradients, but are less likely to affect the gradient orientations. Therefore, we reduce the influence of large gradient magnitudes by thresholding the values in the unit feature vector to each be no larger than 0.2, and then renormalizing to unit length. This means that matching the magnitudes for large gradients is no longer as important, and that the distribution of orientations has greater emphasis. The value of 0.2 was determined experimentally using images containing differing illuminations for the same 3D objects.</em></blockquote><p><strong>That’s all, I really hope that this article will help you understand the SIFT algorithm. Because I am still a learner of Computer Vision, if you have any questions or suggestions, feel free to contact me. I will be really happy if you can point out my mistake. 🤪</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7233dc60f37" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/sift-scale-invariant-feature-transform-c7233dc60f37">SIFT(Scale-invariant feature transform)</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Otsu’s method]]></title>
            <link>https://medium.com/@MinghaoNing/otsus-method-db49e2f85093?source=rss-5b4ecb9c2828------2</link>
            <guid isPermaLink="false">https://medium.com/p/db49e2f85093</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Minghao Ning]]></dc:creator>
            <pubDate>Fri, 29 Mar 2019 14:09:28 GMT</pubDate>
            <atom:updated>2019-03-29T14:09:28.635Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, I’m learning some classic computer vision methods from the <a href="https://courses.cs.washington.edu/courses/cse576/18sp/notes/index.html">notes</a>, and I find it a good habit to take some notes, so here I am.<br>This is my first time to write an article at Medium. So there may be some mistakes, and I will be really happy that you point out the mistakes.<br><strong>In this article, I will show you the mathematical details of Otsu’s method, and I will show you an example, you can view the </strong><a href="https://github.com/NingMingHao/Otsu-method"><strong>Python code here</strong></a><strong> although it’s a really easy example.</strong></p><h3>Introduction</h3><p><a href="https://en.wikipedia.org/wiki/Otsu%27s_method">Otsu’s method</a> can be used to the reduction of a grayscale image to a binary image. It assumes that the image contains two classes of pixels following <strong>bi-modal histogram</strong> (foreground pixels and background pixels). <strong>The key is that this method can generate a threshold based on the histogram of an image.</strong><br>As the histogram figure shows, it finds the threshold <strong><em>t</em></strong> that minimizes the weighted sum of <strong>within-group variances (we will discuss it later， note that it refers to variations caused by differences within individual groups )</strong> for the two groups that result from separating the gray tones at value t.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/180/1*gtfwOvvEuzMJTQaDm4JVXQ.png" /></figure><p>So, how can we find the proper <strong><em>t</em></strong> ? Before we start, let’s catch up some knowledge of probability theory.</p><h3>Algorithm details</h3><p>The variance is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/195/1*4AqR3msWlB8E3MtAX_qfcg.png" /></figure><p>That is all we need. <strong>:)</strong></p><p>And the <strong>within-group variance</strong> is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/241/1*JmRKLWs_5dD76-KCs-5-7Q.png" /></figure><p>where weights ω0 and ω1 are the possibilities of each group (Grp0’s intensity is lesser than <strong><em>t</em></strong> ), σ0 and σ1 are the variances of each group. Suppose we have a normalized histogram <strong>P</strong> with L bins. The mathematical definition:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*ZE7cTr1cqD2sy5qyF6laeA.png" /></figure><p>So, now, we know how to calculate the <strong>within-group variance</strong>, it seems we are ready, but there some tricks to simplify the algorithm, so it can run faster.<br>Here comes the <a href="https://doi.org/10.1109%2FTSMC.1979.4310076"><strong>between-group variance</strong></a>, contrary to <strong>within-group variance</strong>, it refers to the variations caused by differences between groups. <strong>Between-group variance</strong> is the difference between the <strong>variance of the total histogram distribution</strong> and <strong>within-group variance</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*8-XEbsrRwplTiukpwPNeug.png" /></figure><p>So minimizing <strong>within-group variance</strong> is equal to maximizing the <strong>between-group variance</strong>.<br>Now let’s have a look at the formula of <strong>between-group variance</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*5t2l99vHrJy9OqVBVXApEw.png" /></figure><p>Following is how we get this formula:</p><p>Keep in mind that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/186/1*-V4ogx7dGyFxIxlj7v3LXA.png" /></figure><p>if we set <strong><em>t=L</em></strong>, we can get the <strong>E(X)</strong>.<br>According to the definition of E(x²) and E(X) we can easily find:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/244/1*B4S0pGaOhizynJCZaMWWOg.png" /></figure><p>and</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*ZbmzJYDlkhnDXQZRpUVipQ.png" /></figure><p>So,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*AxpZ54JR_NIeT0mJiASkCQ.png" /></figure><p><strong><em>Now, all we need to do is only to get two arrays of the ω0 and E(X0), then we can get the between-group variance. Finally, we use argmax to get the proper threshold t.</em></strong></p><h3>Code</h3><pre>img_hist = np.histogram(img_flattened,bins=255)<br>brightness_list = img_hist[1][1:].astype(int) #ignore the first element<br>hist_counts = img_hist[0]<br>normed_hist_counts = hist_counts/hist_counts.sum()<br>weighted_prob = brightness_list*normed_hist_counts</pre><pre>omiga_arr = normed_hist_counts.cumsum()<br>Ex_arr = weighted_prob.cumsum()</pre><pre>def calculate_between_group_variance(threshold):<br>    eps = 1e-10 #avoid divide by zero<br>    omiga0 = omiga_arr[threshold-1]<br>    Ex0 = Ex_arr[threshold-1]<br>    between_group_variance = omiga0*(Ex0-EX)**2/(1-omiga0+eps)<br>    return between_group_variance<br>    <br>inter_class_variance_arr = np.array(list(map(calculate_between_group_variance,brightness_list)))</pre><h3>Example:</h3><p>I got the origin grayscale image from <a href="https://en.wikipedia.org/wiki/File:Image_processing_pre_otsus_algorithm.jpg">wiki</a>,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7UyNEnm9vo3JzTwCL7W73w.png" /></figure><p>and the histogram is shown as follow(note that I have set count number of 255 as the number of 254, because the sky is overexposed):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*BACjIW0CP-PAPUQ5b_6SQQ.png" /></figure><p>the between_group_variance is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*3YXnsrWYbayCBwVskDeZ9A.png" /></figure><p>and the final binary map is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5bkXdAwofo09tGxVp76Yeg.png" /></figure><h3>That is all! Thanks for your time! If you have any question, feel free to contact me. :)</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db49e2f85093" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>