<?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 Aditya Negi on Medium]]></title>
        <description><![CDATA[Stories by Aditya Negi on Medium]]></description>
        <link>https://medium.com/@adistar121999?source=rss-d8f6f4c24373------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*SC6A-s_765XqSWvk3PR4Ug.jpeg</url>
            <title>Stories by Aditya Negi on Medium</title>
            <link>https://medium.com/@adistar121999?source=rss-d8f6f4c24373------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 12:42:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@adistar121999/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[Road lane detection using OpenCV]]></title>
            <link>https://medium.com/analytics-vidhya/road-lane-detection-using-opencv-3e2d2740a4d?source=rss-d8f6f4c24373------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e2d2740a4d</guid>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[canny-edge-detection]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[projects-of-the-week]]></category>
            <category><![CDATA[hough-transform]]></category>
            <dc:creator><![CDATA[Aditya Negi]]></dc:creator>
            <pubDate>Fri, 24 Jul 2020 22:52:25 GMT</pubDate>
            <atom:updated>2020-07-25T16:10:13.878Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s implement a road lane detector using OpenCV.</p><p>We would be using Canny Edge Detector and Hough Lines for the same. Their functions can be implemented using OpenCV.</p><p>For the working of Canny Edge Detector from scratch, check out my last <a href="https://medium.com/analytics-vidhya/canny-edge-detector-7b8037fa0764">article</a> in which I gave an in-depth explanation for it. Canny Edge Detector plays a vital role in this model, hence having its knowledge helps.</p><h4>MODEL PIPELINE</h4><p>First of all let’s import Matplotlib, OpenCV, and Numpy libraries. For those, who don’t know Matplotlib is a visualization tool whereas OpenCV is an image processing library.</p><pre>import <strong>matplotlib</strong>.pylab as plt<br>import <strong>cv2</strong><br>import <strong>numpy</strong> as np</pre><p>Now, the pipeline of the model will be as follows:<br>1. Read the image and convert it to RGB format. Get its height and width and define a region of interest which is required for the Lane Detection.<br>2. Then convert the image to GRAY format because the Canny Edge Detector takes only GRAY images as input. Pass the image to Canny Edge Detector.<br>3. Now, mask the image by the region of interest defined earlier.<br>4. Then apply Hough transform to the image which is a feature extraction technique that gives instances of objects within a certain class of shapes. In our case, the shape will be a line thus we will use HoughLines function.<br>5. Finally, the transform will return the detected lines and we will draw it in our image as output.</p><p>Now let’s make a helper function which masks the image to the region of interest. One can proceed without doing so but this helps to achieve better results. We are simply defining our region of interest in the image.</p><p>We can mask the image by giving vertices and input image to the function.</p><pre>def <strong>region_of_interest</strong>(img,vertices): <br>    mask = np.<strong>zeros_like</strong>(img) <br>    channel_count=img.shape[2]         <br>    match_mask_color=  255   #(255,) * channel_count<br>    cv2.<strong>fillPoly</strong>(mask,vertices,match_mask_color)<br>    masked_image=cv2.<strong>bitwise_and</strong>(img,mask) <br>    return masked_image</pre><p>Also, let’s implement a helper function that draws given lines on the image. The lines needed to be drawn will be available after Hough Transform.</p><pre>def <strong>draw_the_lines</strong>(img,lines): <br>  imge=np.<strong>copy</strong>(img)     <br>  blank_image=np.<strong>zeros</strong>((imge.shape[0],imge.shape[1],3),\<br>                                                   dtype=np.uint8)<br>  for line in lines:  <br>    for x1,y1,x2,y2 in line:<br>      cv2.<strong>line</strong>(blank_image,(x1,y1),(x2,y2),(0,255,0),thickness=3)<br>      imge = cv2.<strong>addWeighted</strong>(imge,0.8,blank_image,1,0.0) <br>  return imge</pre><pre>**<strong>Note</strong>: Mind the indents, as it could differ for your IDE. Code link would be provided at the end.</pre><p>cv2.line() is used to draw lines on the blank image, which is added to the original image via cv2.addWeighted().</p><p>To read further about these functions refer to the <a href="https://opencv-python-tutroals.readthedocs.io/en/latest/index.html">original documentation</a>.</p><h4>Probabilistic Hough Line Transform</h4><p>Let’s understand the Probabilistic Hough Line Transform. If you are not interested in the theory you can skip this section.</p><p>Hough Transform is a popular technique to detect any shape if you can represent that shape in mathematical form. It can detect the shape even if it is broken or distorted a little bit. <br>For in-depth understanding, refer to the official <a href="https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_houghlines/py_houghlines.html?highlight=houghlinesp">documentation</a>.</p><p>In short, a line can be represented as p= x cosQ + y sinQ, where p is the perpendicular distance and Q is the angle made by it with the x-axis.</p><p>In Hough Line Transform, we create an array with two columns and multiple rows where columns denote values of p and Q which are initially set to zero.<br>Size of the array depends on the accuracy we want, Now from a given Canny Edge image we iterate these different values of p and Q all over the edge points and deduce best continuous lines and save that value of p and Q. Later this will be used for drawing lines on the original image.</p><p>Probabilistic Hough Transform is an optimization of Hough Transform. It doesn’t take all the edge points into consideration, instead, take only a random subset of points and that is sufficient for line detection.</p><pre> cv2.<strong>HoughLinesP</strong>(edges,rho,theta,threshold,minLineLength,maxLineGap)</pre><p><strong>‘edges’</strong> is the edge image, <strong>‘rho’</strong> is p or the perpendicular distance.<br><strong>‘np.pi/180’</strong> is the range of <strong>theta </strong>or the angle in radians, here -180 to 180.<br><strong>‘threshold’</strong> needs to be fine-tuned according to the image.<br>‘<strong>minLineLength</strong>’ is the minimum length of the line, Line segments shorter than this are rejected.<br>‘<strong>maxLinGap</strong>’ is the maximum allowed gap between the line segments to treat them as single line.</p><p>The input image used is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nTOydMnvcxnn_EcAdQUVOg.png" /><figcaption>img.png</figcaption></figure><p><strong>Step1</strong>: Read the image and convert it to RGB format. Get its height and width and define a region of interest which is required for the Lane Detection.</p><pre>image=cv2.<strong>imread</strong>(&#39;img.png&#39;)<br>image=cv2.<strong>cvtColor</strong>(image,cv2.COLOR_BGR2RGB)<br>height=image.shape[0]<br>width=image.shape[1]<br>region_of_interest_coor=[(0,height),(0,400),(width/2,height/3),\     <br>                                                     (width,height)]</pre><p><strong>Step2</strong>: Convert the image to GRAY format and pass the image to Canny.</p><pre>gray_image = cv2.<strong>cvtColor</strong>(image,cv2.COLOR_RGB2GRAY)<br>canny_image = cv2.<strong>Canny</strong>(gray_image,100,200)</pre><p><strong>Step3: </strong>Now, mask the canny image by the region of interest defined earlier.</p><pre>cropped=<strong>region_of_interest</strong>(canny_image,\<br>np.array([region_of_interest_coor],np.int32))</pre><p><strong>Step4: </strong>Apply Probabilistic Hough Line Transform to the masked canny image.</p><pre>lines = cv2.<strong>HoughLinesP</strong>(cropped,rho=2,theta=np.pi/120,threshold=120\<br>,lines=np.array([]),minLineLength=20,maxLineGap=35)</pre><p><strong>Step5</strong>: Draw the lines by draw_the_lines() defined earlier, by using ‘lines’ returned by the HoughLinesP() and plot the resultant image.</p><pre>image_with_lines = <strong>draw_the_lines</strong>(image,lines) plt.<strong>imshow</strong>(image_with_lines)<br>plt.<strong>show</strong>()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*sMYd4AMWxmrWFmbDs8WV5A.png" /><figcaption>Output image: ‘image_with_lines’</figcaption></figure><p>This sums up the implementation of the model. Here is the <a href="https://github.com/negiaditya/PROJECT-Road_Lane_detection/blob/master/detector.py">code</a>.</p><p>This can be easily scaled up for video or real-time. We just need to use cv2.VideoCapture(‘vid.mp4’) function which returns frame by frame image and each image can be passed through the model we just created.</p><pre>cap = cv2.<strong>VideoCapture</strong>(&#39;video.mp4&#39;)</pre><pre>while cap.<strong>isOpened</strong>():<br>   ret, frame = cap.<strong>read</strong>()    <br>   frame = process(frame)    <br>   cv2.<strong>imshow</strong>(&#39;frame&#39;, frame)    <br>   if cv2.<strong>waitKey</strong>(1) &amp; 0xFF == ord(&#39;q&#39;):<br>      break </pre><pre>cap.<strong>release</strong>()<br>cv2.<strong>destroyAllWindows</strong>()</pre><p>‘cap’ has every frame of the image which passed through the function process() i.e the Lane Detection model we created.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FqPf25obODRM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DqPf25obODRM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FqPf25obODRM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a74361e5ec0bd21d0f0433c006c02510/href">https://medium.com/media/a74361e5ec0bd21d0f0433c006c02510/href</a></iframe><p>I’ve already implemented it and the code can be found <a href="https://github.com/negiaditya/PROJECT-Road_Lane_detection/blob/master/video.py">here</a>.</p><p>Finally, I wanted to acknowledge <a href="https://www.youtube.com/channel/UCs6nmQViDpUw0nuIx9c_WvA">Programming Knowledge</a> for their work.</p><p>Thank you for reading, If you liked this article, do clap and you can read more such articles <a href="http://medium.com/@adistar121999">here</a>.</p><p>Cheers!<br>Happy Learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e2d2740a4d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/road-lane-detection-using-opencv-3e2d2740a4d">Road lane detection using OpenCV</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Birdman: Flying via ignorance]]></title>
            <link>https://medium.com/worldofcinema/birdman-flying-via-ignorance-9bd94536b56?source=rss-d8f6f4c24373------2</link>
            <guid isPermaLink="false">https://medium.com/p/9bd94536b56</guid>
            <category><![CDATA[movie-recommendation]]></category>
            <category><![CDATA[hollywood]]></category>
            <category><![CDATA[explanation]]></category>
            <category><![CDATA[movie-review]]></category>
            <category><![CDATA[cinema]]></category>
            <dc:creator><![CDATA[Aditya Negi]]></dc:creator>
            <pubDate>Tue, 21 Jul 2020 23:05:10 GMT</pubDate>
            <atom:updated>2020-07-21T23:33:57.368Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>- ” I’m nothing. I’m not even here. “</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tpxEtylxqZs7TG6FhxTDyg.jpeg" /></figure><p><strong>General Wiki</strong></p><blockquote><strong>Director</strong>: Alejandro González Iñárritu<br><strong>Screenplay</strong>: Alejandro González Iñárritu, Nicolás Giacobone<br><strong>IMDB &amp; RottenTomatoes Ratings</strong>: 7.7 &amp; 91%<br><strong>Genre</strong>: Drama, Romance, Dark-comedy<br><strong>Language</strong>: English<br><strong>Running time</strong>: 119 minutes</blockquote><h4>Our take</h4><p>To rise is human’s nature, which can be assisted by innovation, curiosity or even ignorance. Through continuous hustle and struggle, we humans also learn to fly. The force keeping us down is just rendering our brain, to overcome we need a little push and life gives more than a little push. We better take that as an opportunity or we’ll never be able to fly.</p><p><strong>Rating: 4.5/5</strong></p><h4>Who should watch?</h4><p>If you are someone who adores camera work and a sucker of details, this movie will not fail you. <br>Anyone, who likes realistic and therapeutical cinema should give this piece of art a chance.<br>Even if all this don’t resonate but if you are in for engaging and strong plot, your expectations will be thoroughly delivered.</p><p>I would finally recommend this to anyone who is here for the best cinema.</p><h4>Why watch?</h4><p>The star cast is extremely talented with the likes of Michael Keaton, Naomi Watts, Edward Norton, Emma Stone, Andrea Riseborough and many more.</p><p>If you want to see some top tier direction and cinematography, you need to check this out. The most bewildering aspect of the movie is its direction having multiple seamless long takes and also superb pace.</p><p>The way human insecurities and vulnerabilities are explored in the movie is relatable and engaging. You may get some remarkable insights on the human psyche and how we see our relationships.</p><p>Surreal viewing experience and engaging visuals.</p><p>Altogether a masterpiece, with an exceptional cast, script, cinematography and direction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*0z9K_Jr8XsDEYskQrE75GA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*VxeQUnN8eWNo2GTd66poRQ.jpeg" /></figure><h4>Synopsis</h4><p>Riggan Thomson, a fading cinema superhero, plans to resurrect his career with a passionate Broadway production. However, during rehearsals, his co-star is injured forcing him to hire a new actor who is redundant and a pain for Riggan. Meanwhile, he is confronting problems with his daughter. Throughout the film, he is haunted by his most famous character ‘Birdman’ as he experiences many surreal events, including stepping off a rooftop and flying over the streets of New York.</p><h3>Explained</h3><blockquote>Spoiler! Spoiler! Spoiler! Spoiler! Spoiler! Spoiler! Spoiler! Spoiler!</blockquote><p>If you have already watched the movie and wondering, Was he flying? How did he shot himself? What’s in his head and what’s real?</p><p>This<a href="https://www.looper.com/207960/the-ending-of-birdman-explained/#:~:text=The%20symbols%20in%20Birdman&amp;text=Riggan%20flies%20to%20escape%20his,his%20more%20passionate%20creative%20endeavors."> article</a> gives an in-depth explanation of all those questions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*xCI6jUQPErpB2fXtv2RBmA.jpeg" /></figure><p>Well, as ambiguous it may seem but there was a sense of circulatory and consistency throughout the movie. In starting we saw, Riggan levitating and in the end, he flies away from the hospital. Both of these occurrences were not explained in the movie, unlike all other scenes which were accompanied by an explanation.</p><p>The circle completes as Riggan takes on the role of -Birdman and creating a global image of the superhero in the early stage of his career. In the end, it was time for -Birdman to repay by giving Riggan his ability of flight.</p><p>Or one can simply say, we are not subjected to ground truth created by the universe. We can create our own worlds where we can fly or have super strength. It just varies when someone else perceives our world similarly.</p><p>In the end, Riggan’s daughter resolves all her issues with her father and then she looks out of the window and smiles thus indicating that she too believes in the world created by Riggan or Riggan allows her to be a part of it.</p><p>Hope you like this review and if you do, don’t forget to clap.</p><p>Follow the publication for many more reviews publishing every week.</p><p>Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9bd94536b56" width="1" height="1" alt=""><hr><p><a href="https://medium.com/worldofcinema/birdman-flying-via-ignorance-9bd94536b56">Birdman: Flying via ignorance</a> was originally published in <a href="https://medium.com/worldofcinema">WorldofCinema</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Canny edge detector]]></title>
            <link>https://medium.com/analytics-vidhya/canny-edge-detector-7b8037fa0764?source=rss-d8f6f4c24373------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b8037fa0764</guid>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[canny-edge-detection]]></category>
            <dc:creator><![CDATA[Aditya Negi]]></dc:creator>
            <pubDate>Tue, 23 Jun 2020 15:45:08 GMT</pubDate>
            <atom:updated>2020-06-24T15:37:05.606Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s implement a canny edge detector and remove borders of the input images in Python.</p><p>Let’s dive right into implementation as we have already discussed the basics of edge detection in the <a href="https://medium.com/analytics-vidhya/introduction-to-computer-vision-5e104ed62ef1">article</a>. Do give a read for a better understanding of the process.</p><h4><strong>Data visualization</strong></h4><p><strong>Input image loading and visualization</strong></p><p>We are using Matplotlib, NumPy, OS and CV2 libraries for the visualisation.</p><p>The given function takes input a given directory and returns an array of images which were present in the directory. Here, we have loaded the array in the variable ‘plates’.</p><pre><strong><br>def</strong> load_data(dir_name = &#39;plates&#39;):<br>    imgs=[]<br>    <strong>for</strong> root,dirs,files <strong>in</strong> os.walk(dir_name):<br>        <strong>for</strong> filename <strong>in</strong> files:<br>            <strong>if</strong> filename.endswith(&#39;.png&#39;):<br>                img=cv2.imread(os.path.join(root,filename),0)<br>                imgs.append(img)<br>    <strong>return</strong> np.array(imgs)<br><br>plates = load_data()</pre><p>Now we will visualize the loaded images. The auxiliary function ‘visualize()’ displays the images given as argument.</p><pre><strong>def</strong> visualize(imgs, format=<strong>None</strong>):<br>    plt.figure(figsize=(20, 40))<br>    <strong>for</strong> i, img <strong>in</strong> enumerate(imgs):<br>        <strong>if</strong> img.shape[0] == 3:<br>            img = img.transpose(1,2,0)<br>        plt_idx = i+1<br>        plt.subplot(3, 3, plt_idx)    <br>        plt.imshow(img, cmap=format)<br>    plt.show()<br><br>visualize(plates, &#39;gray&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*FwIErwX0ZOMh8Oy9HX9J6w.png" /><figcaption>The output of the ‘visualize’ function</figcaption></figure><h4>Canny detector implementation</h4><p><strong>Canny detection algorithm</strong></p><ol><li><em>Noise reduction:</em> To remove noise, the image is smoothed by Gaussian blur with the kernel of size 5 X 5 and sigma = 1.4. Since the sum of the elements in the Gaussian kernel equals 1, the kernel should be normalized before the convolution.</li><li><em>Calculating gradients:</em> When the image <em>I</em> is smoothed, the derivatives <em>Ix</em> and <em>Iy</em> w.r.t <em>x</em> and <em>y</em> are calculated. They can be implemented by convolving image <em>I</em> with Sobel kernels <em>Kx</em> and <em>Ky</em>, respectively. Then, the magnitude G and slope theta are calculated.</li><li><em>Non-maximum suppression.</em> For each pixel find two neighbours (in the positive and negative gradient directions, supposing that each neighbour occupies the angle of <em>pi/4</em>, and <em>0</em> is the direction straight to the right). If the magnitude of the current pixel is greater than the magnitudes of the neighbours, nothing changes, otherwise, the magnitude of the current pixel is set to zero.</li><li><em>Double threshold.</em> The gradient magnitudes are compared with two specified threshold values, the first one is less than the second. The gradients that are smaller than the low threshold value are suppressed; the gradients higher than the high threshold value are marked as strong ones and the corresponding pixels are included in the final edge map. All the rest gradients are marked as weak ones and pixels corresponding to these gradients are considered in the next step.</li><li><em>Edge tracking by hysteresis.</em> Since a weak edge pixel caused from true edges will be connected to a strong edge pixel, pixel <em>w</em> with weak gradient is marked as edge and included in the final edge map if and only if it is involved in the same blob (connected component) as some pixel <em>s </em>with strong gradient. In other words, there should be a chain of neighbour weak pixels connecting <em>w</em> and <em>s</em>(the neighbours are 8 pixels around the considered one).</li></ol><p>Let’s define the function using this algorithm.</p><pre><strong>from</strong>  <strong>skimage.feature</strong> <strong>import</strong> canny<br><strong>from</strong> <strong>skimage</strong> <strong>import</strong> dtype_limits<br><strong>from</strong> <strong>scipy</strong> <strong>import</strong> ndimage<br><strong>from</strong> <strong>scipy.ndimage.filters</strong> <strong>import</strong> convolve, gaussian_filter<br><br><br><strong>def</strong> Canny_detector(img,highThreshold=91,lowThreshold=31):<br>  img=np.array(img,dtype=float) <em>#convert to float to prevent clipping values</em><br><br>  <em>#step1: Noise reduction</em><br>  img=gaussian_filter(img,sigma=1.4,truncate=3.3)<br><br>  <em>#step2: Calculating gradients</em><br>  Kx=[[-1,0,1],[-2,0,2],[-1,0,1]]  <em>#Sobel filters</em><br>  Ky=[[1,2,1],[0,0,0],[-1,-2,-1]]<br>  Ix=convolve(img,Kx)<br>  Iy=convolve(img,Ky)<br>  grad=np.hypot(Ix,Iy) <em>#magnitude of gradient</em><br>  theta=np.arctan2(Iy,Ix) <em>#slope theta of gradient</em><br><br>  thetaQ=(np.round(theta*(5.0/np.pi))+5)%5 <em>#Quantize direction</em><br><br>  <em>#step3: Non-maximum suppression</em><br>  gradS=grad.copy()<br>  <strong>for</strong> r <strong>in</strong> range(img.shape[0]):<br>    <strong>for</strong> c <strong>in</strong> range(img.shape[1]):<br>      <em>#suppress pixels at the image edge</em><br>      <strong>if</strong> r==0 <strong>or</strong> r==img.shape[0]-1 <strong>or</strong> c==0 <strong>or</strong> c==img.shape[1]-1:<br>        gradS[r,c]=0<br>        <strong>continue</strong><br>      tq=thetaQ[r,c] % 4<br><br>      <strong>if</strong> tq==0: <em>#0 is E-W (horizontal)</em><br>        <strong>if</strong> grad[r,c] &lt;= grad[r,c-1] <strong>or</strong> grad[r,c]&lt;=grad[r,c+1]:<br>          gradS[r,c]=0<br>      <strong>if</strong> tq==1: <em>#1 is NE-SW</em><br>        <strong>if</strong> grad[r,c] &lt;= grad[r-1,c+1] <strong>or</strong> grad[r,c]&lt;=grad[r+1,c-1]:<br>          gradS[r,c]=0<br>      <strong>if</strong> tq==2: <em>#2 is N-S (vertical)</em><br>        <strong>if</strong> grad[r,c] &lt;= grad[r-1,c] <strong>or</strong> grad[r,c]&lt;=grad[r+1,c]:<br>          gradS[r,c]=0<br>      <strong>if</strong> tq==3: <em>#3 is NW-SE</em><br>        <strong>if</strong> grad[r,c] &lt;= grad[r-1,c-1] <strong>or</strong> grad[r,c]&lt;=grad[r+1,c+1]:<br>          gradS[r,c]=0<br><br>    <em>#step4: Double threshold</em><br>    strongEdges=(gradS&gt;highThreshold)<br>    <em>#strong has value 2, weak has value 1</em><br>    thresholdEdges=np.array(strongEdges,dtype=np.uint8)+ (gradS&gt;lowThreshold)<br><br>    <em>#step5: Edge tracking by hysterisis</em><br>    <em>#Find weak edge pixels near strong edge pixels</em><br>    finalEdges=strongEdges.copy()<br>    currentPixels=[]<br>    <strong>for</strong> r <strong>in</strong> range(1,img.shape[0]-1):<br>      <strong>for</strong> c <strong>in</strong> range(1,img.shape[1]-1):<br>        <strong>if</strong> thresholdEdges[r,c]!=1:<br>          <strong>continue</strong> <em>#Not a weak pixel</em><br>          <br>        <em>#get a 3X3 patch</em><br>        localPatch=thresholdEdges[r-1:r+2,c-1:c+2]<br>        patchMax=localPatch.max()<br>        <strong>if</strong> patchMax==2:<br>          currentPixels.append((r,c))<br>          finalEdges[r,c]=1<br>        <br>    <em>#Extend strong edges based on current pixels</em><br>    <strong>while</strong> len(currentPixels) &gt; 0:<br>      newPixels=[]<br>      <strong>for</strong> r,c <strong>in</strong> currentPixels:<br>        <strong>for</strong> dr <strong>in</strong> range(-1,2):<br>            <strong>for</strong> dc <strong>in</strong> range(-1,2):<br>              <strong>if</strong> dr==0 <strong>and</strong> dc==0:<br>                <strong>continue</strong><br>              r2=r+dr<br>              c2=c+dc<br>              <strong>if</strong> thresholdEdges[r2,c2]==1 <strong>and</strong> finalEdges[r2,c2]==0:<br>                <em>#copy this weak pixel to final result</em><br>                newPixels.append((r2,c2))<br>                finalEdges[r2,c2]=1<br>      currentPixels= newPixels<br>        <br>    <strong>return</strong> finalEdges</pre><p>Now let’s apply the function on the input images.</p><pre>canny_imgs = []<br><strong>for</strong> img <strong>in</strong> plates:<br>    canny_img = Canny_detector(img)<br>    canny_imgs.append(canny_img)<br>    <br>visualize(canny_imgs, &#39;gray&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*mQuiXNVQmI446-82vZC3Sg.png" /><figcaption>The output of the ‘visualize’ function depicting canny edge transform</figcaption></figure><h4>The borders removal</h4><p>It is worth noting that there is a framing from all sides in most of the images. This framing can appreciably worsen the quality of channels alignment. Here, we find the borders on the plates using the Canny edge detector, and crop the images according to these edges.</p><p><strong>Borders removal algorithm</strong></p><p>The borders can be removed in the following way:</p><ul><li>Apply the Canny edge detector to the image (already applied).</li><li>Find the rows and columns of the frame pixels. For example, in case of upper bound we will search for the row in the neighbourhood of the upper edge of the image (e.g. 5% of its height).</li><li>For each row let us count the number of edge pixels (obtained using Canny detector) it contains. Having these number let us find two maximums among them. Two rows corresponding to these maximums are edge rows.</li><li>As there are two colour changes in the frame (firstly, from light scanner background to the dark tape and then from the tape to the image), we need the second maximum that is further from the image border.</li><li>The row corresponding to this maximum is the crop border. In order not to find two neighbouring peaks, non-maximum suppression should be implemented: the rows next to the first maximum are set to zero, and after that, the second maximum is searched for.</li></ul><p>Let’s define the function using this algorithm.</p><pre><strong>def</strong> remove_borders(img, canny_img):   <br>    dx = int(img.shape[1] * 0.05) <br>    <strong>return</strong> img[dx : -dx, dx : -dx]</pre><p>Now let’s apply the function on canny images obtained earlier.</p><pre>cropped_imgs = []<br><em>#crop borders</em><br><strong>for</strong> i, img <strong>in</strong> enumerate(plates):<br>    cropped_imgs.append(remove_borders(img, canny_imgs[i]))<br><br>visualize(cropped_imgs, &#39;gray&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*b4y7U4BkkcZC_5aKAuTP6g.png" /><figcaption>The output of ‘visualize’ function depicting border removal</figcaption></figure><p>Let’s compare all the images :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*FwIErwX0ZOMh8Oy9HX9J6w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*mQuiXNVQmI446-82vZC3Sg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*b4y7U4BkkcZC_5aKAuTP6g.png" /><figcaption>Input images (left), Canny edge detector transformed image (centre), Borders removed from images (right)</figcaption></figure><p>Thank you, for reading!</p><p>Happy learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b8037fa0764" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/canny-edge-detector-7b8037fa0764">Canny edge detector</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Computer Vision]]></title>
            <link>https://medium.com/analytics-vidhya/introduction-to-computer-vision-5e104ed62ef1?source=rss-d8f6f4c24373------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e104ed62ef1</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[edge-detection]]></category>
            <category><![CDATA[convolution]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[image]]></category>
            <dc:creator><![CDATA[Aditya Negi]]></dc:creator>
            <pubDate>Wed, 10 Jun 2020 00:10:47 GMT</pubDate>
            <atom:updated>2020-06-23T15:52:18.953Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>“To see is to know what is where by looking.”</blockquote><h4><strong>What is Computer Vision?</strong></h4><p>Well, the name defines itself. It is the ability of a computer to gain vision. When I say ‘vision’, I don&#39;t mean eyes will pop out of the system haunting us or simply providing a camera to the computer.</p><p>Vision is the ability to intercept details and features from an input image or video. But how would a computer perceive these characteristics since it only deals with 1s and 0s. The field of Computer Vision answers all these questions and has been around for the last 70 years!</p><p>Our main objective would be to answer any question regarding an image which can be answered by humans. This is also known as ‘Turing Test’ in artificial intelligence named after Alan Turing.</p><p>Computer Vision has been an integral part of the rise of artificial intelligence in the last couple of decades. With numerous applications in this field, the primary applications could be distinguished as:</p><p><strong>1. Object Detection: </strong>It answers the basic question, “what and where?”.<br>What is the image/video exhibiting and ‘where’ or the location of the object in the image/video. It includes applications like ‘<em>optical character recognition’, ‘object tracking’, ‘activity recognition</em><strong>’ </strong>etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ABi6irBxDXeOECQUfYRZGQ.jpeg" /><figcaption>The model detects various object along with their locations.</figcaption></figure><p><strong>2.Object properties and attributes: </strong>After we have detected the object, what next? How about we extract their features and details? This makes model much powerful as now not only it detects object but also perceives information. It has some very important applications like <em>‘Medical Imagining’, ‘Face Detection and Verification’, ‘Image Retrieval’ </em>etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*GOndDJCwoZFuG5rnZRIF9Q.jpeg" /><figcaption>The model detects the object along with its colour.</figcaption></figure><p><strong>3.Metric vision: </strong>If we want to get details which even humans couldn’t possibly guesstimate, we tune in metric vision which includes many advanced applications like ‘<em>Photogrammetry’</em>(the science of making measurements from photographs<strong>), ‘</strong><em>Image-based 3D modelling’ </em>and many more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Cdwm4OvjPj0Z0kku9xjZvw.png" /><figcaption>The input to photogrammetry is photographs, and the output is typically a map, a drawing, a measurement, or a 3D model of some real-world object or scene.</figcaption></figure><h4>What are optical Images?</h4><p>Optical images are defined as 2D representations of a physical object, obtained by the propagation of light through some optical system, depicting object contour and features or simply an image or video captured by a camera.</p><p>Digital colour images are 3D array where each array has pixel values which represent the colour density in the range [0,255]. These arrays are filters of predefined colours, thus all the colour images consist of three colours ‘RED’, ‘GREEN’, and ‘BLUE’. This representation is termed as ‘RGB’ and combining these primary colours all the different colours are obtained as per ‘trichromatic colour theory’. The digital ‘GRAYSCALE’ images are a 2D array of colours ‘BLACK’ and ‘WHITE’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/415/1*zHRpQxSwkAS21w_GqOLNfg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*gh92eauloIqxGrNGVeV2Lw.png" /><figcaption>The tricolour filters(left) are combined to give optical images(right).</figcaption></figure><h4>Various defects occurring in images</h4><p>Our images can be defective in many ways and it impairs the system when extracting useful features and attributes. Some common defects are:<br><strong>Low contrast: </strong>Image blends light and dark areas, creating a more flat photo. <br><strong>Wrong colours: </strong>Images depict objects in colours that differ from reality. <strong><br>Noise: </strong>Random variation of brightness or colour information.<strong><br>Blur: </strong>It occurs due to sudden movements of objects or camera.<strong><br>Non-uniform lightning: </strong>Light is irregularly placed over the image.</p><p>To overcome these problems we apply image processing.<br><strong>Image processing</strong> is a method to perform some operations on an image, in order to get an enhanced image or to extract some useful information from it. It is a type of <strong>signal processing</strong> in which input is an image and output may be image or characteristics/features associated with that image. <br>Thus, an important part of <strong>computer vision</strong>.</p><h4>Why image processing?</h4><ol><li>Image improvement for human perception. It improves subjective image quality.</li><li>Image improvement for machine perception. It simplifies the subsequent image analysis and recognition.</li><li>Image transformation for technical purposes such as change of image resolution or aspect ratio for display on the device.</li><li>To get artistic impressions from cool visual effects.</li></ol><p>To start in the field of computer vision we should try to extract the most basic feature of the images i.e edges. Edge detection could be very useful as most semantic and shape information can be encoded in the edges.</p><h3>Edge detection</h3><p><strong>Goal</strong>: Identify sudden changes or discontinuities in the image, referred to as edges. They are more compact than pixels and carry more information.</p><p><strong>Intensity function: </strong>It<strong> </strong>gives the <strong>intensity</strong> of a channel at every position or pixel where darker the pixel lesser is the intensity value.</p><p><strong>Edges: </strong>An edge can thus be defined as a place of rapid change in image intensity function. We can further locate edges using image gradients.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*53bURYmS8fzD6xkzx-nYkQ.png" /></figure><p><strong>Image gradient:</strong> The gradient is the first-order differentiation of the intensity function and it points in the direction of the most rapid increase in intensity.<br>It is denoted as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*jtgYqNXwPOutn_FQruAAnQ.png" /><figcaption>The partial derivative of intensity function in both the axes.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/159/1*GuODE9oiJmYLnsd59tbaZw.png" /><figcaption>the gradient direction</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/94/1*DDxzmo_uJZGgMOBSVk9Fag.png" /><figcaption>the gradient magnitude</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/180/1*viA9NpQdgZ46-NYzAwfQZA.png" /></figure><p>Noise in images could be disadvantageous in edge detection. It causes unwanted spikes in the first derivative of image intensity which could make the real edges disappear. So it becomes very important to smooth the image intensity curve through image averaging to reduce noise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/286/1*3Ia-4A4EPsnOjXTutiMukQ.png" /><figcaption>Noise fades the edges</figcaption></figure><p>Gradient magnitude estimation is not a complete edge detection. We need precision i.e gradients strength along thick ridges is larger thus propagating only significant edges. Also, there should be connectivity between edge points.</p><p>This can be done by ‘<strong>canny edge detector</strong>’ which uses ‘<strong>convolution</strong>’ in place of gradient magnitude detection but the idea remains the same. We can approximate partial derivative with finite-difference.</p><h4>Convolution</h4><p>This is regarded as the most important mathematical operation in image processing. We convolve a kernel or mask which is a small matrix to the input image which in turn gives astonishing results like sharpening, blurring, embossing and even edge detection. Different kernels are used for different tasks. The mathematical formula for convolution is given as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*QCja4tFjcH_gf0lPRbiGXw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*oeLOgg1QuoiA5CwFHmXmrg.png" /><figcaption>‘I’ is the input matrix, ’K’ is the kernel and I*K is the output.</figcaption></figure><p>Let&#39;s apply it on the image channels and visualise its effect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Eg2xHLCK0kQ3hSHDneAvQ.png" /><figcaption>We can see, with the given kernel we get edges of the input image.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*JV66nd6t3XkZZZ0XOGjYYQ.png" /><figcaption>Some more kernel features</figcaption></figure><p>Convolution has a very important role in ‘<strong>canny edge detector</strong>’ and <strong>‘Sobel kernels’ </strong>are used to get edges denoted by Kx and Ky.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/1*v5AWmvYfN_xcw7YnRrZnWw.png" /><figcaption>Sobel filters</figcaption></figure><p>The Canny edge detector is implemented in this <a href="https://medium.com/@adistar121999/canny-edge-detector-7b8037fa0764?sk=11133eb22c80ce6fd6e384afd0d124ad">article</a>. Do take a look for python implementation.</p><p>Thank you, for reading!</p><p>Happy learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e104ed62ef1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/introduction-to-computer-vision-5e104ed62ef1">Introduction to Computer Vision</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>