<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8523114731285043891</id><updated>2024-11-01T04:08:07.667-07:00</updated><title type='text'>CYRIL L. YOMI</title><subtitle type='html'>All purposes blog (programming, ect ...)</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ycyril.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8523114731285043891/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://ycyril.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Cyril Yomi</name><uri>http://www.blogger.com/profile/01414384071897949120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8523114731285043891.post-8801990213618483198</id><published>2010-04-01T21:41:00.000-07:00</published><updated>2010-04-04T13:41:21.781-07:00</updated><title type='text'>Processing image with convolution matrix using vb.net - image processing</title><content type='html'>The purpose of this code is to implement an image processing filter using the filter matrix (with vb.net) I use as document the filter chapter of the GIMP documentation. (GIMP is actually the tool I usually use for some assignments in the webdesign).&lt;br /&gt;here is the link: &lt;a href=&quot;http://docs.gimp.org/en/plug-in-convmatrix.html&quot;&gt;http://docs.gimp.org/en/plug-in-convmatrix.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;so it&#39;s actually not too difficult to implement. here the code:&lt;br /&gt;&lt;br /&gt;&#39;get the library&lt;br /&gt;Imports System.Drawing.Bitmap&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;&#39; Create a Bitmap object from a file.&lt;br /&gt;Dim myBitmap As New Bitmap (&quot;imagepath&quot;)  &#39; example (&quot;C:\whatever\ ...&quot;)&lt;br /&gt;&#39; Create a bitmap object result&lt;br /&gt;Dim mybmpResult As Bitmap&lt;br /&gt;&lt;br /&gt;&#39;set kernel matrix (this very one is an edge detector)&lt;br /&gt;&#39;you can change the values to obtain a blur effect, or sharpen or whatever&lt;br /&gt;&#39;check the kernel values in the link&lt;br /&gt;&lt;br /&gt;   Dim k11, k12, k13, k21, k22, k23, k31, k32, k33 As Double&lt;br /&gt;&lt;br /&gt;   k11 = 0&lt;br /&gt;   k12 = -1&lt;br /&gt;   k13 = 0&lt;br /&gt;   k21 = -1&lt;br /&gt;   k22 = 3   &#39;here I use 3 instead of 4&lt;br /&gt;   k23 = -1&lt;br /&gt;   k31 = 0&lt;br /&gt;   k32 = -1&lt;br /&gt;   k33 = 0&lt;br /&gt;&lt;br /&gt;&#39;Now it&#39;s actually a simple matrix calculation of the pixels in 2 loops&lt;br /&gt;&#39;You can check the link to see how it s done.&lt;br /&gt;&lt;br /&gt;Dim Ycount As Integer&lt;br /&gt;   For Ycount = 1 To myBitmap.Height - 2&lt;br /&gt;&lt;br /&gt;       Dim Xcount As Integer&lt;br /&gt;&lt;br /&gt;       For Xcount = 1 To myBitmap.Width - 2&lt;br /&gt;&lt;br /&gt;&#39;you need 9 matrix elements, and for each of those,&lt;br /&gt;&#39;you need the RED, GREEN AND BLUE value&lt;br /&gt;&#39;to form 1 pixel&lt;br /&gt;&lt;br /&gt;&#39;values of first row in RGB&lt;br /&gt;           Dim x11R, x12R, x13R As Integer&lt;br /&gt;           Dim x11G, x12G, x13G As Integer&lt;br /&gt;           Dim x11B, x12B, x13B As Integer&lt;br /&gt;&lt;br /&gt;&#39;values of second row in RGB&lt;br /&gt;           Dim x21R, x22R, x23R As Integer&lt;br /&gt;           Dim x21G, x22G, x23G As Integer&lt;br /&gt;           Dim x21B, x22B, x23B As Integer&lt;br /&gt;&lt;br /&gt;&#39;values of third row in RGB&lt;br /&gt;           Dim x31R, x32R, x33R As Integer&lt;br /&gt;           Dim x31G, x32G, x33G As Integer&lt;br /&gt;           Dim x31B, x32B, x33B As Integer&lt;br /&gt;&lt;br /&gt;&#39;assign all those values according to the bitmap object&lt;br /&gt;&lt;br /&gt;           x11R = myBitmap.GetPixel(Xcount - 1, Ycount - 1).R&lt;br /&gt;           x11G = myBitmap.GetPixel(Xcount - 1, Ycount - 1).G&lt;br /&gt;           x11B = myBitmap.GetPixel(Xcount - 1, Ycount - 1).B&lt;br /&gt;&lt;br /&gt;           x12R = myBitmap.GetPixel(Xcount, Ycount - 1).R&lt;br /&gt;           x12G = myBitmap.GetPixel(Xcount, Ycount - 1).G&lt;br /&gt;           x12B = myBitmap.GetPixel(Xcount, Ycount - 1).B&lt;br /&gt;&lt;br /&gt;           x13R = myBitmap.GetPixel(Xcount + 1, Ycount - 1).R&lt;br /&gt;           x13G = myBitmap.GetPixel(Xcount + 1, Ycount - 1).G&lt;br /&gt;           x13B = myBitmap.GetPixel(Xcount + 1, Ycount - 1).B&lt;br /&gt;&lt;br /&gt;           &#39;---&lt;br /&gt;&lt;br /&gt;           x21R = myBitmap.GetPixel(Xcount - 1, Ycount).R&lt;br /&gt;           x21G = myBitmap.GetPixel(Xcount - 1, Ycount).G&lt;br /&gt;           x21B = myBitmap.GetPixel(Xcount - 1, Ycount).B&lt;br /&gt;&lt;br /&gt;           x22R = myBitmap.GetPixel(Xcount, Ycount).R&lt;br /&gt;           x22G = myBitmap.GetPixel(Xcount, Ycount).G&lt;br /&gt;           x22B = myBitmap.GetPixel(Xcount, Ycount).B&lt;br /&gt;&lt;br /&gt;           x23R = myBitmap.GetPixel(Xcount + 1, Ycount).R&lt;br /&gt;           x23G = myBitmap.GetPixel(Xcount + 1, Ycount).G&lt;br /&gt;           x23B = myBitmap.GetPixel(Xcount + 1, Ycount).B&lt;br /&gt;&lt;br /&gt;           &#39;---&lt;br /&gt;&lt;br /&gt;           x31R = myBitmap.GetPixel(Xcount - 1, Ycount + 1).R&lt;br /&gt;           x31G = myBitmap.GetPixel(Xcount - 1, Ycount + 1).G&lt;br /&gt;           x31B = myBitmap.GetPixel(Xcount - 1, Ycount + 1).B&lt;br /&gt;&lt;br /&gt;           x32R = myBitmap.GetPixel(Xcount, Ycount + 1).R&lt;br /&gt;           x32G = myBitmap.GetPixel(Xcount, Ycount + 1).G&lt;br /&gt;           x32B = myBitmap.GetPixel(Xcount, Ycount + 1).B&lt;br /&gt;&lt;br /&gt;           x33R = myBitmap.GetPixel(Xcount + 1, Ycount + 1).R&lt;br /&gt;           x33G = myBitmap.GetPixel(Xcount + 1, Ycount + 1).G&lt;br /&gt;           x33B = myBitmap.GetPixel(Xcount + 1, Ycount + 1).B&lt;br /&gt;&lt;br /&gt;&#39;matrix calculation of R&lt;br /&gt;           x22R = (x11R * k11 + x12R * k21 + x13R * k31) + (x21R * k12 + x22R * k22 + x23R * k32) + (x31R * k13 + x32R * k23 + x33R * k33)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&#39;matrix calculation of G&lt;br /&gt;           x22G = (x11G * k11 + x12G * k21 + x13G * k31) + (x21G * k12 + x22G * k22 + x23G * k32) + (x31G * k13 + x32G * k23 + x33G * k33)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&#39;matrix calculation of B&lt;br /&gt;           x22B = (x11B * k11 + x12B * k21 + x13B * k31) + (x21B * k12 + x22B * k22 + x23B * k32) + (x31B * k13 + x32B * k23 + x33B * k33)&lt;br /&gt;&lt;br /&gt;&#39;if it happens, that the calculation result is negativ or greater than 255, then&lt;br /&gt;&#39;keep it in the range&lt;br /&gt;&lt;br /&gt;             If  x22R &lt; 0 Then&lt;br /&gt;&lt;br /&gt;                    x22R = 0&lt;br /&gt;&lt;br /&gt;                End If&lt;br /&gt;&lt;br /&gt;                If x22R &gt; 255 Then&lt;br /&gt;&lt;br /&gt;                    x22R = 255&lt;br /&gt;&lt;br /&gt;                End If&lt;br /&gt;&lt;br /&gt;                If x22G &lt; 0 Then&lt;br /&gt;&lt;br /&gt;                    x22G = 0&lt;br /&gt;&lt;br /&gt;                End If&lt;br /&gt;&lt;br /&gt;                If x22G &gt; 255 Then&lt;br /&gt;&lt;br /&gt;                    x22G = 255&lt;br /&gt;&lt;br /&gt;                End If&lt;br /&gt;&lt;br /&gt;                If x22B &lt; 0 Then&lt;br /&gt;&lt;br /&gt;                    x22B = 0&lt;br /&gt;&lt;br /&gt;                End If&lt;br /&gt;&lt;br /&gt;                If x22B &gt; 255 Then&lt;br /&gt;&lt;br /&gt;                    x22B = 255&lt;br /&gt;&lt;br /&gt;                End If&lt;br /&gt;&lt;br /&gt;&#39;then for each pixel result, set the result in the new bitmap object&lt;br /&gt;&lt;br /&gt;           mybmpResult.SetPixel(Xcount - 1, Ycount, Color.FromArgb(x22R, x22G, x22B))&lt;br /&gt;&lt;br /&gt;           &#39;#############################################&lt;br /&gt;&lt;br /&gt;       Next Xcount&lt;br /&gt;   Next Ycount&lt;br /&gt;&lt;br /&gt;&#39;You can also view the result in a pictureBox, you just drag and drop in visual basic, and then&lt;br /&gt;PictureBox1.Image = mybmp</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8523114731285043891/posts/default/8801990213618483198'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8523114731285043891/posts/default/8801990213618483198'/><link rel='alternate' type='text/html' href='http://ycyril.blogspot.com/2010/04/funny.html' title='Processing image with convolution matrix using vb.net - image processing'/><author><name>Cyril Yomi</name><uri>http://www.blogger.com/profile/01414384071897949120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry></feed>