<?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>CRoNuXs.NeT</title>
	<atom:link href="http://www.cronuxs.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cronuxs.net</link>
	<description>A developer? A scientist? I&#039;ll never know!</description>
	<lastBuildDate>Thu, 19 Apr 2012 22:47:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>First Demo &#8220;Threshold.py&#8221;</title>
		<link>http://www.cronuxs.net/2011/08/first-demo/</link>
		<comments>http://www.cronuxs.net/2011/08/first-demo/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 01:52:09 +0000</pubDate>
		<dc:creator>Fernando PN</dc:creator>
				<category><![CDATA[ImageProcessing]]></category>
		<category><![CDATA[Numpy]]></category>
		<category><![CDATA[Pil]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.cronuxs.net/?p=43</guid>
		<description><![CDATA[How about we open a image, do some calcs and save it? This is the first post about it, so how can we open a image in python? usually images can be in a lot of different formats so to solve this puzze and to simplify the thinks a little bit &#8230; <a href="http://www.cronuxs.net/2011/08/first-demo/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[<p>How about we open a image, do some calcs and save it?</p>
<p>This is the first post about it, so how can we open a image in python? usually images can be in a lot of different formats so to solve this puzze and to simplify the thinks a little bit we will use a tool called PIL (Python Imaging Library).</p>
<p>To simplify the things we will use a library called NumPy (Numeric Python) to deal with matrices.</p>
<p>First of all, if you don&#8217;t have PIL or Numpy install it. On ubuntu you can just type &#8220;<strong>sudo apt-get install python-imaging python-numpy</strong>&#8221;</p>
<p>File: <strong>threshold.py</strong></p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #808080; font-style: italic;">#-*- coding: utf-8 -*-</span>
<span style="color: #808080; font-style: italic;"># </span>
<span style="color: #808080; font-style: italic;"># Author: Fernando Paolieri Neto | 07-aug-2011</span>
<span style="color: #808080; font-style: italic;"># </span>
&nbsp;
<span style="color: #808080; font-style: italic;">#import needed libraries</span>
<span style="color: #ff7700;font-weight:bold;">import</span> Image
<span style="color: #ff7700;font-weight:bold;">import</span> numpy
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#function to convert numpy to pil</span>
<span style="color: #ff7700;font-weight:bold;">def</span> array2pil<span style="color: black;">&#40;</span>arr<span style="color: black;">&#41;</span>:
  nd <span style="color: #66cc66;">=</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>arr.<span style="color: black;">shape</span><span style="color: black;">&#41;</span>
  x <span style="color: #66cc66;">=</span> arr.<span style="color: black;">astype</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'B'</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> nd <span style="color: #66cc66;">==</span> <span style="color: #ff4500;">2</span>:
    d<span style="color: #66cc66;">,</span> h<span style="color: #66cc66;">,</span> w <span style="color: #66cc66;">=</span> <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: #66cc66;">,</span><span style="color: black;">&#41;</span> + arr.<span style="color: black;">shape</span>
    mode <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'L'</span>
  <span style="color: #ff7700;font-weight:bold;">elif</span> nd <span style="color: #66cc66;">==</span> <span style="color: #ff4500;">3</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> arr.<span style="color: black;">dtype</span>.<span style="color: black;">char</span> <span style="color: #66cc66;">==</span> <span style="color: #483d8b;">'?'</span>:
      <span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">TypeError</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">&quot;Binary array cannot be RGB&quot;</span>
    h<span style="color: #66cc66;">,</span> w<span style="color: #66cc66;">,</span> d <span style="color: #66cc66;">=</span> arr.<span style="color: black;">shape</span>
    <span style="color: #ff7700;font-weight:bold;">if</span>   d <span style="color: #66cc66;">==</span> <span style="color: #ff4500;">1</span>: mode <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'L'</span>
    <span style="color: #ff7700;font-weight:bold;">elif</span> d <span style="color: #66cc66;">==</span> <span style="color: #ff4500;">3</span>: mode <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'RGB'</span>
    <span style="color: #ff7700;font-weight:bold;">elif</span> d <span style="color: #66cc66;">==</span> <span style="color: #ff4500;">4</span>: mode <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'RGBA'</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
      <span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">TypeError</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">&quot;Array first dimension must be 1, 3 or 4 (%d)&quot;</span> % d
  <span style="color: #ff7700;font-weight:bold;">else</span>:
    <span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">TypeError</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">&quot;Array must have 2 or 3 dimensions (%d)&quot;</span> % nd
  pil <span style="color: #66cc66;">=</span> Image.<span style="color: black;">fromstring</span><span style="color: black;">&#40;</span>mode<span style="color: #66cc66;">,</span> <span style="color: black;">&#40;</span>w<span style="color: #66cc66;">,</span>h<span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> x.<span style="color: black;">tostring</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> arr.<span style="color: black;">dtype</span>.<span style="color: black;">char</span> <span style="color: #66cc66;">==</span> <span style="color: #483d8b;">'?'</span>:
    pil <span style="color: #66cc66;">=</span> pil.<span style="color: black;">point</span><span style="color: black;">&#40;</span><span style="color: #ff7700;font-weight:bold;">lambda</span> i: i<span style="color: #66cc66;">&gt;</span><span style="color: #ff4500;">0</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'1'</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">return</span> pil
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ <span style="color: #66cc66;">==</span> <span style="color: #483d8b;">&quot;__main__&quot;</span>:
  <span style="color: #808080; font-style: italic;">#read image using Pil</span>
  img <span style="color: #66cc66;">=</span> Image.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">#convert Pil image to Numpy Array</span>
  F <span style="color: #66cc66;">=</span> numpy.<span style="color: black;">asarray</span><span style="color: black;">&#40;</span>img<span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">#if -B is passed by argument we will do the averege</span>
  <span style="color: #808080; font-style: italic;">#of the 3 channels R,G and B</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #483d8b;">'-B'</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span>:
    F<span style="color: #66cc66;">=</span> <span style="color: black;">&#40;</span>F<span style="color: black;">&#91;</span>:<span style="color: #66cc66;">,</span>:<span style="color: #66cc66;">,</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>/<span style="color: #ff4500;">3</span> + F<span style="color: black;">&#91;</span>:<span style="color: #66cc66;">,</span>:<span style="color: #66cc66;">,</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>/<span style="color: #ff4500;">3</span> + F<span style="color: black;">&#91;</span>:<span style="color: #66cc66;">,</span>:<span style="color: #66cc66;">,</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>/<span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">#Do the threshold</span>
  F <span style="color: #66cc66;">=</span> <span style="color: black;">&#40;</span>F<span style="color: #66cc66;">&gt;</span><span style="color: #ff4500;">127</span><span style="color: black;">&#41;</span>*numpy.<span style="color: black;">uint8</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">255</span><span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">#If -I is passed, the image will be inverted</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #483d8b;">'-I'</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span>:
    F <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">255</span>-F
&nbsp;
  <span style="color: #808080; font-style: italic;">#convert to pil</span>
  img <span style="color: #66cc66;">=</span> array2pil<span style="color: black;">&#40;</span>F<span style="color: black;">&#41;</span>
  <span style="color: #808080; font-style: italic;">#save output</span>
  img.<span style="color: black;">save</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;out.png&quot;</span><span style="color: #66cc66;">,</span><span style="color: #483d8b;">&quot;PNG&quot;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div></div>

<p>Save your file as threshold.py or get it from <a title="GitRepository" href="http://labs.cronuxs.net/wiki/index.php?title=GitRepository">GitRepository</a>.</p>
<p>Now lets us just run the program (example on ubuntu):</p>
<pre>
python threshold.py imageIn.jpg -B -I
</pre>
<p>If you set <strong>-B</strong> will be used the average, and if you set <strong>-I</strong> the image will be inverted.<br />
As result a new image called out.png will be generated.</p>
<p>A demo was build in CGI to show this code running on a webserver. <a title="http://labs.cronuxs.net/demo/threshold.py " href="http://labs.cronuxs.net/demo/threshold.py " target="_blank"> Threshold Demo </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cronuxs.net/2011/08/first-demo/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Encoding, Decoding, Weird characters??</title>
		<link>http://www.cronuxs.net/2011/08/encoding-decoding-weird-characters/</link>
		<comments>http://www.cronuxs.net/2011/08/encoding-decoding-weird-characters/#comments</comments>
		<pubDate>Sun, 07 Aug 2011 13:55:54 +0000</pubDate>
		<dc:creator>Fernando PN</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Decoding]]></category>
		<category><![CDATA[Encoding]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.cronuxs.net/?p=27</guid>
		<description><![CDATA[Have you haver had a problem with charset encoding? I had, a lot. Why? us on Brazil use a lot of &#8216;é&#8217;, &#8216;ç&#8217;, &#8216;ã&#8217;, &#8216;í&#8217; and a lot of other chars that have different definitions on different encoding like (ISO 8895-1, UTF-8 and some others). So often happens that you &#8230; <a href="http://www.cronuxs.net/2011/08/encoding-decoding-weird-characters/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[<p>Have you haver had a problem with charset encoding?</p>
<p>I had, a lot. Why? us on Brazil use a lot of &#8216;é&#8217;, &#8216;ç&#8217;, &#8216;ã&#8217;, &#8216;í&#8217; and a lot of other chars that have different definitions on different encoding like (ISO 8895-1, UTF-8 and some others).</p>
<p>So often happens that you wrote a full document on latex (by example), and save it as UTF-8 on your text editor. When u open it on the next time all your special characters will be like %% and other weird characters.</p>
<p>To prevent it try always to put on your source code a explicitly definition of the used encoding on the header of your file.</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#-*- coding: utf-8 -*-</span></pre></td></tr></table></div></div>

<p>Most of the text editors will read this header and understand that you want to use UTF-8.</p>
<p>If you really need to convert between charsets, this is the source of a iso8859-1 to utf-8 conversor and vice versa. It can be easily be changed to other encodings.</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_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="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> my_decode<span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span>:
  raw <span style="color: #66cc66;">=</span> s.<span style="color: black;">decode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;iso8859-1&quot;</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">return</span> raw.<span style="color: black;">encode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;utf-8&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff7700;font-weight:bold;">try</span>:
  txt <span style="color: #66cc66;">=</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">print</span> my_decode<span style="color: black;">&#40;</span>txt.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
  txt.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">IndexError</span>:
  <span style="color: #ff7700;font-weight:bold;">print</span> my_decode<span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">stdin</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
  <span style="color: #dc143c;">sys</span>.<span style="color: black;">stdin</span>.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div></div>

<p>How hard is that?<br />
I&#8217;am sure that this core runs on python 2.x. It may need some changes to work on python 3.0 like the use of the print function.</p>
<p>Updated Version on our <a title="GitRepository" href="http://labs.cronuxs.net/git/" target="_blank">GitRepository</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cronuxs.net/2011/08/encoding-decoding-weird-characters/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Git and Svn Repositories</title>
		<link>http://www.cronuxs.net/2011/08/git-and-svn-repositories/</link>
		<comments>http://www.cronuxs.net/2011/08/git-and-svn-repositories/#comments</comments>
		<pubDate>Sun, 07 Aug 2011 07:06:09 +0000</pubDate>
		<dc:creator>Fernando PN</dc:creator>
				<category><![CDATA[Repositories]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Svn]]></category>

		<guid isPermaLink="false">http://www.cronuxs.net/?p=17</guid>
		<description><![CDATA[For now we have two links, one for git and another for svn repositories for existing projects, for now they are password protected because they are not ready. We are preparing to release one by one of then. Some of then as OpenSource programs other ones as free software. For &#8230; <a href="http://www.cronuxs.net/2011/08/git-and-svn-repositories/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[<p>For now we have two links, one for git and another for svn repositories for existing projects, for now they are password protected because they are not ready.</p>
<p>We are preparing to release one by one of then. Some of then as OpenSource programs other ones as free software.</p>
<p>For now we have a <a title="GitRepository" href="http://labs.cronuxs.net/wiki/index.php?title=GitRepository">GitRepository</a> with all the content provided by this site and by the <a href="http://labs.cronuxs.net/" title="Labs.CRoNuXs.NeT" target="_blank">Labs.CRoNuXs.NeT</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cronuxs.net/2011/08/git-and-svn-repositories/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello Everybody</title>
		<link>http://www.cronuxs.net/2011/08/hello-world/</link>
		<comments>http://www.cronuxs.net/2011/08/hello-world/#comments</comments>
		<pubDate>Sun, 07 Aug 2011 03:13:08 +0000</pubDate>
		<dc:creator>Fernando PN</dc:creator>
				<category><![CDATA[RealLife]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.cronuxs.net/?p=1</guid>
		<description><![CDATA[This is actually my first post in English. I am native from Brazil, and will try on this website show my achievements and accomplishments in academy life and real life. I really hope you all enjoy. Sorry about my english. Ill do my best. Selec All Code:1 2 from __future__ import print_function &#8230; <a href="http://www.cronuxs.net/2011/08/hello-world/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="size-medium wp-image-9 aligncenter" title="Dr Nick Simpsons" src="http://www.cronuxs.net/wp-content/uploads/2011/08/Dr-Nick-Simpsons-300x288.png" alt="" width="300" height="288" /></p>
<p><span>This is actually my first post in English. I am native from Brazil, and will try on this website show my achievements and accomplishments in academy life and real life. I really hope you all enjoy.</span></p>
<p>Sorry about my english. Ill do my best.</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">__future__</span> <span style="color: #ff7700;font-weight:bold;">import</span> print_function
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Hello World&quot;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># support for python 3.0</span></pre></td></tr></table></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.cronuxs.net/2011/08/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

