<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OpenPeta &#187; Image Processing</title>
	<atom:link href="http://openpeta.com/index.php/category/image-processing/feed/" rel="self" type="application/rss+xml" />
	<link>http://openpeta.com</link>
	<description>Open Mind ....  Open Source ...</description>
	<lastBuildDate>Wed, 21 Jul 2010 03:20:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Watermark Images  &#8211; A Software for Adding Text into Images</title>
		<link>http://openpeta.com/index.php/2010/03/watermark-images-a-software-for-adding-text-into-images/</link>
		<comments>http://openpeta.com/index.php/2010/03/watermark-images-a-software-for-adding-text-into-images/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 02:06:38 +0000</pubDate>
		<dc:creator>ANTHONIRAJ</dc:creator>
				<category><![CDATA[Image Processing]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Ubuntu Linux]]></category>
		<category><![CDATA[Weblog]]></category>

		<guid isPermaLink="false">http://www.openpeta.com/?p=717</guid>
		<description><![CDATA[Every time when i post article in my blog, i used to display some images,  also i will think about adding  &#8220;my blog name:OpenPeta.com&#8221; as a watermark into the images for ownership purpose [In OpenPeta all content and images are published under Open source and creative common licenses , so any one can copy and [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Every time when i post article in my blog, i used to display some images,  also i will think about adding  &#8220;my blog name:OpenPeta.com&#8221; as a watermark into the images for ownership purpose [In OpenPeta all content and images are published under Open source and creative common licenses , so any one can copy and distribute the content with author name. for that purpose only i want to add watermark in images] . but In Ubuntu i could not do that task , Windows Live has that features of adding watermark and border to images .  I always look into sourceforge.net for open source softwares, today i found one simple Java based watermark software for adding text into images. lets analyze it.</p>
<p style="text-align: justify;">
<div id="attachment_718" class="wp-caption aligncenter" style="width: 310px"><a href="http://openpeta.com/wp-content/uploads/2010/03/Screenshot1.jpg"><img class="size-medium wp-image-718" title="WatermarkImages from SourceForge.net" src="http://www.openpeta.com/wp-content/uploads/2010/03/Screenshot-300x187.jpg" alt="WatermarkImages from SourceForge.net" width="300" height="187" /></a><p class="wp-caption-text">WatermarkImages from SourceForge.net</p></div>
<p style="text-align: justify;"><strong>What is Image Watermarking?</strong></p>
<p style="text-align: justify;">Image watermarking is the technique for hiding data within the image, the data can be a text or image. This technique is used for preventing unauthorized ownership of  particular image . There are two types of watermarking</p>
<ol>
<li>Visible Watermarking &#8211; watermarked text will visible inside the image</li>
<li>Invisible Watermarking &#8211; watermarked text will not be visible to others , only the owner can extract the text using decoding algorithm and key.</li>
</ol>
<p><strong>Image Watermarking Software -WatermarkImages</strong></p>
<p>WatermarkImages is a software which is used for adding text with various colors and fonts into image. it can be downloaded from <a href="http://sourceforge.net/projects/watermarkimages/">http://sourceforge.net/projects/watermarkimages/</a> sourceforge website.  This software is written in Java , so you need Java interpreter or run time environment to run this software .</p>
<div id="attachment_719" class="wp-caption aligncenter" style="width: 310px"><a href="http://openpeta.com/wp-content/uploads/2010/03/Screenshot-Hitesh-S-J-Sathawane-Watermarker-2.01.jpg"><img class="size-medium wp-image-719" title="Watermarker 2.0" src="http://www.openpeta.com/wp-content/uploads/2010/03/Screenshot-Hitesh-S-J-Sathawane-Watermarker-2.0-300x246.jpg" alt="" width="300" height="246" /></a><p class="wp-caption-text">Watermarker 2.0</p></div>
<p><strong>Adding Watermark into Images</strong></p>
<p>After downloading binary or jar file of this software from the net , simply extract the file and store it into some folder. for runnung this software , goto terminal and tyoe</p>
<blockquote>
<h3><strong>#java -jar WaterMarker2.1.jar</strong></h3>
</blockquote>
<div id="attachment_720" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.openpeta.com/wp-content/uploads/2010/03/Screenshot-Text-Watermarking-Panel.jpg"><img class="size-medium wp-image-720" title="Screenshot-Text Watermarking Panel" src="http://www.openpeta.com/wp-content/uploads/2010/03/Screenshot-Text-Watermarking-Panel-300x296.jpg" alt="" width="300" height="296" /></a><p class="wp-caption-text">Text Watermarking Panel</p></div>
<p>This command will open the GUI window of this software, then select the image which you want to add text , and Enter the text then  click start button ,  The watermarked image will be ready for you within a second.</p>
]]></content:encoded>
			<wfw:commentRss>http://openpeta.com/index.php/2010/03/watermark-images-a-software-for-adding-text-into-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2D Graphics Using C in Linux [ Graphics.h in Linux ]</title>
		<link>http://openpeta.com/index.php/2009/09/2d-graphics-using-c-in-linux-graphics-h-in-linux/</link>
		<comments>http://openpeta.com/index.php/2009/09/2d-graphics-using-c-in-linux-graphics-h-in-linux/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 00:18:22 +0000</pubDate>
		<dc:creator>ANTHONIRAJ</dc:creator>
				<category><![CDATA[Image Processing]]></category>
		<category><![CDATA[Open Source Programming]]></category>
		<category><![CDATA[Ubuntu Linux]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.openpeta.com/?p=512</guid>
		<description><![CDATA[Most of technical people are trying to migrate from windows to Linux now a days , but they are facing lot of problems with Linux . they do not even know the forums and blogs of Linux which would be useful for finding answer to their query. The main problem of open source is choosing [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Most of technical people are trying to migrate from windows to Linux now a days , but they are facing lot of problems with Linux . they do not even know the forums and blogs of Linux which would be useful for finding answer to their query. The main problem of open source is choosing right one for user need. Because so many open source softwares are available for a single thing. Surely user need some supportive forum or website to find that one . open Peta is also doing that job. The idea of this  post coming to my mind from my college friend . One of my colleague asked me about computer graphics program in Linux using C programming language. the questions is</p>
<blockquote><p>How to draw line, circle , or 2D graphics in Linux Using C or C++?</p></blockquote>
<p>I was searching Internet and found some softwares for developing graphics applications in Linux. that softwares are listed here</p>
<ol>
<li>GTK+   &#8211; Gnome Tool Kit</li>
<li>QT  -  The X toolkit</li>
<li>SVGALIB   [ #include&lt;vgagl.h&gt; ]</li>
<li>libgraph [ #include&lt;graphics.h&gt; ]</li>
</ol>
<p style="text-align: justify;">GTK and QT are simple and used for high level Graphical User Interface [ GUI ] development. SVGALIB and libgraph is used for 2D graphics in Linux .  the syntax and functions are some what different for beginners  [specially the user from windows ] but most of users familiar with windows graphics.h header file in C and C++ , so we can move for libgraph which is exact one for windows graphics user . libgraph is an implementation of the Turbo C graphics API (graphics.h) on GNU/Linux using SDL [ Simple Direct Media Player ]. The library requires SDL for primitive graphics and SDL. First you need to install the following dependency packages using synaptic package manager in Ubuntu Linux to develop the graphics applications properly.</p>
<ul>
<li>SDL Library</li>
</ul>
<div id="attachment_516" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.openpeta.com/wp-content/uploads/2009/09/graph3.png"><img class="size-medium wp-image-516" title="Installing SDL Library" src="http://www.openpeta.com/wp-content/uploads/2009/09/graph3-300x187.png" alt="Installing SDL Library" width="300" height="187" /></a><p class="wp-caption-text">Installing SDL Library</p></div>
<ul>
<li>GUILE &#8211; GNU&#8217;s Ubiquitous Intelligent Language for Extension</li>
</ul>
<p style="text-align: justify;">
<div id="attachment_517" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.openpeta.com/wp-content/uploads/2009/09/graph5.png"><img class="size-medium wp-image-517" title="GUILE Installation" src="http://www.openpeta.com/wp-content/uploads/2009/09/graph5-300x187.png" alt="GUILE Installation" width="300" height="187" /></a><p class="wp-caption-text">GUILE Installation</p></div>
<ul>
<li> After installing these two packages , download the<a href="http://ftp.twaren.net/Unix/NonGNU/libgraph/" target="_blank"> libgraph</a> and install in your system</li>
</ul>
<blockquote><p>#sudo su</p>
<p>#tar -xzvf <a href="http://ftp.twaren.net/Unix/NonGNU/libgraph/libgraph-1.0.2.tar.gz">libgraph-1.0.2.tar.gz</a></p>
<p>#cd libgraph-1.0.2</p>
<p>#make</p>
<p># make install</p></blockquote>
<p>For better understanding , watch this video given here &#8230;.<br />
<center><object width="425" height="344" align="center"><param name="movie" value="http://www.youtube.com/v/hqYlnIn___E&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/hqYlnIn___E&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></center><br />
Developing Graphics Application</p>
<p>1. Open your favorite text editor and type the following code</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;stdio.h&quot;</span>
<span style="color: #339933;">#include &quot;graphics.h&quot;</span>
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #993333;">int</span> gd<span style="color: #339933;">=</span>DETECT<span style="color: #339933;">,</span> gm<span style="color: #339933;">=</span>VGAMAX<span style="color: #339933;">;</span>
initgraph<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>gd<span style="color: #339933;">,&amp;</span>amp<span style="color: #339933;">;</span>gm<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
moveto<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
setcolor<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
rectangle<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">50</span><span style="color: #339933;">,</span><span style="color: #0000dd;">50</span><span style="color: #339933;">,</span><span style="color: #0000dd;">500</span><span style="color: #339933;">,</span><span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>kbhit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
closegraph<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>2. Now compile the program with lgraph library</p>
<blockquote><p>#gcc line.c -lgraph -o output</p>
<p>#./output</p></blockquote>
<p>If you get any error in this line like</p>
<p>./output: error while loading shared libraries: libgraph.so.1: cannot open shared object file: No such file or directory</p>
<p>Do the following</p>
<blockquote><p>sudo cp /usr/local/lib/libgraph.* /usr/lib</p></blockquote>
<p>3. Now one new window will open , there you will get the output Rectangle in Red color.</p>
<div id="attachment_521" class="wp-caption aligncenter" style="width: 310px"><a href="http://openpeta.com/wp-content/uploads/2009/09/out2.png"><img class="size-medium wp-image-521" title="Output Window" src="http://www.openpeta.com/wp-content/uploads/2009/09/out-300x187.png" alt="Output Window" width="300" height="187" /></a><p class="wp-caption-text">Output Window</p></div>
<p>The advantage of libgraph is very easy to remember the syntax  [ all functions are same as turbo c graphics.h ] . still if you are facing any problem to develop graphics applications using this , send your problems through comment page of this post.</p>
]]></content:encoded>
			<wfw:commentRss>http://openpeta.com/index.php/2009/09/2d-graphics-using-c-in-linux-graphics-h-in-linux/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Grabbing Pixels from PGM Image using C</title>
		<link>http://openpeta.com/index.php/2009/03/grabbing-pixels-from-pgm-image-using-c/</link>
		<comments>http://openpeta.com/index.php/2009/03/grabbing-pixels-from-pgm-image-using-c/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 18:18:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C Language]]></category>
		<category><![CDATA[Image Processing]]></category>

		<guid isPermaLink="false">http://www.openpeta.com/2009/03/24/grabbing-pixels-from-pgm-image-using-c/</guid>
		<description><![CDATA[#include&#60;stdio.h&#62; #include&#60;string.h&#62; #include&#60;stdlib.h&#62; /* * Auhtor : Anthoniraj.A * Date : 24/03/2009 */ int** imageRead&#40;char imageName&#91;&#93;&#41;; void imageWrite&#40;int** pels&#41;; int width, height; int **pixels; unsigned char *charImage; &#160; int** imageRead&#40;char imageName&#91;&#93;&#41; &#123; FILE* fp; &#160; //PGM Headers Variable Declaration char* type; int *ptr; int q, i, j; &#160; char header&#91;100&#93;; //Open file for Reading in [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include&lt;stdio.h&gt;</span>
<span style="color: #339933;">#include&lt;string.h&gt;</span>
<span style="color: #339933;">#include&lt;stdlib.h&gt;</span>
<span style="color: #808080; font-style: italic;">/*
* Auhtor : Anthoniraj.A
* Date : 24/03/2009
*/</span>
<span style="color: #993333;">int</span><span style="color: #339933;">**</span> imageRead<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> imageName<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">void</span> imageWrite<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #339933;">**</span> pels<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> width<span style="color: #339933;">,</span> height<span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> <span style="color: #339933;">**</span>pixels<span style="color: #339933;">;</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>charImage<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span><span style="color: #339933;">**</span> imageRead<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> imageName<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
FILE<span style="color: #339933;">*</span> fp<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//PGM Headers Variable Declaration</span>
<span style="color: #993333;">char</span><span style="color: #339933;">*</span> type<span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> <span style="color: #339933;">*</span>ptr<span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> q<span style="color: #339933;">,</span> i<span style="color: #339933;">,</span> j<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">char</span> header<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">100</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//Open file for Reading in Binary Mode</span>
<span style="color: #666666; font-style: italic;">//fp = fopen(&quot;/home/anthoniraj/image.pgm&quot;,&quot;rb&quot;);</span>
fp <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span>imageName<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;rb&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>fp <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Image does not exist <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//Check the PGM file Type P2 or P5</span>
fgets<span style="color: #009900;">&#40;</span>header<span style="color: #339933;">,</span> <span style="color: #0000dd;">100</span><span style="color: #339933;">,</span> fp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>header<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000dd;">80</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>header<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000dd;">53</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Image is not PGM<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Check the Commnets</span>
fgets<span style="color: #009900;">&#40;</span>header<span style="color: #339933;">,</span> <span style="color: #0000dd;">100</span><span style="color: #339933;">,</span> fp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>header<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #ff0000;">'#'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//printf(&quot;%c\n&quot;, header[0]);</span>
fgets<span style="color: #009900;">&#40;</span>header<span style="color: #339933;">,</span> <span style="color: #0000dd;">100</span><span style="color: #339933;">,</span> fp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Get Width and Height</span>
width <span style="color: #339933;">=</span> strtol<span style="color: #009900;">&#40;</span>header<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>amp<span style="color: #339933;">;</span> ptr<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
height <span style="color: #339933;">=</span> atoi<span style="color: #009900;">&#40;</span>ptr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get Maximum Gray Value</span>
fgets<span style="color: #009900;">&#40;</span>header<span style="color: #339933;">,</span> <span style="color: #0000dd;">100</span><span style="color: #339933;">,</span> fp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
q <span style="color: #339933;">=</span> strtol<span style="color: #009900;">&#40;</span>header<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>amp<span style="color: #339933;">;</span> ptr<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Allocating Array Size</span>
charImage <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> malloc<span style="color: #009900;">&#40;</span>width <span style="color: #339933;">*</span> height <span style="color: #339933;">*</span> <span style="color: #993333;">sizeof</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pixels <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> <span style="color: #339933;">**</span><span style="color: #009900;">&#41;</span> malloc<span style="color: #009900;">&#40;</span>width <span style="color: #339933;">*</span> <span style="color: #993333;">sizeof</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span> lt<span style="color: #339933;">;</span> height<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
pixels<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> malloc<span style="color: #009900;">&#40;</span>height <span style="color: #339933;">*</span> <span style="color: #993333;">sizeof</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Pixel Extraction</span>
fread<span style="color: #009900;">&#40;</span>charImage<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>width <span style="color: #339933;">*</span> height<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #993333;">sizeof</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> fp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span> lt<span style="color: #339933;">;</span> height<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>j <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span> lt<span style="color: #339933;">;</span> width<span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
pixels<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> charImage<span style="color: #009900;">&#91;</span>i <span style="color: #339933;">*</span> width <span style="color: #339933;">+</span> j<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// printf(&quot;%d &quot;,pixels[i][j]);</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">//printf(&quot;\n&quot;);</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Pixel Extraction</span>
fclose<span style="color: #009900;">&#40;</span>fp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">return</span> pixels<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> imageWrite<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #339933;">**</span> pels<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #993333;">int</span> i<span style="color: #339933;">,</span> j<span style="color: #339933;">;</span>
FILE<span style="color: #339933;">*</span> fp1<span style="color: #339933;">;</span>
fp1 <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;out.pgm&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;w&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span> lt<span style="color: #339933;">;</span> height<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>j <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span> lt<span style="color: #339933;">;</span> width<span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
charImage<span style="color: #009900;">&#91;</span>i <span style="color: #339933;">*</span> width <span style="color: #339933;">+</span> j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pels<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
fprintf<span style="color: #009900;">&#40;</span>fp1<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;P5<span style="color: #000099; font-weight: bold;">\n</span>%d<span style="color: #000099; font-weight: bold;">\n</span>%d<span style="color: #000099; font-weight: bold;">\n</span>255<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">,</span> height<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
fwrite<span style="color: #009900;">&#40;</span>charImage<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> width<span style="color: #339933;">*</span>height<span style="color: #339933;">,</span> fp1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
fclose<span style="color: #009900;">&#40;</span>fp1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #993333;">int</span><span style="color: #339933;">**</span> p <span style="color: #339933;">=</span> imageRead<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;sam1.pgm&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
imageWrite<span style="color: #009900;">&#40;</span>p<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://openpeta.com/index.php/2009/03/grabbing-pixels-from-pgm-image-using-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
