<?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>Culture of viruses &#187; Programming</title>
	<atom:link href="http://benjamindeschamps.ca/blog/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://benjamindeschamps.ca/blog</link>
	<description>Usefulness and uselessness by Benjamin Deschamps</description>
	<lastBuildDate>Tue, 17 Nov 2009 17:41:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Processing RADARSAT-2 imagery: reading raw data and saving RGB composites</title>
		<link>http://benjamindeschamps.ca/blog/2009/11/12/processing-radarsat-2-imagery-reading-raw-data-and-saving-rgb-composites/</link>
		<comments>http://benjamindeschamps.ca/blog/2009/11/12/processing-radarsat-2-imagery-reading-raw-data-and-saving-rgb-composites/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 17:23:58 +0000</pubDate>
		<dc:creator>Benjamin</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://benjamindeschamps.ca/blog/?p=23</guid>
		<description><![CDATA[RADARSAT-2 imagery is delivered in GeoTiff files with an additional product.xml file which contains orbit data and ground control points. There are a few Open Source software that you could use to process this data, including RAT Radar Tools, PolSARpro, NEST, Map Ready, etc., and many proprietary software such as Geomatica, ENVI, etc. But, if [...]]]></description>
			<content:encoded><![CDATA[<p>RADARSAT-2 imagery is delivered in GeoTiff files with an additional product.xml file which contains orbit data and ground control points. There are a few Open Source software that you could use to process this data, including <a title="RAT Radar Tools" href="http://radartools.berlios.de/" target="_blank">RAT Radar Tools</a>, <a title="PolSARpro" href="http://earth.esa.int/polsarpro/" target="_blank">PolSARpro</a>, <a title="NEST" href="http://www.array.ca/nest" target="_blank">NEST</a>, <a title="Map Ready" href="http://www.asf.alaska.edu/sardatacenter/softwaretools" target="_blank">Map Ready</a>, etc., and many proprietary software such as Geomatica, ENVI, etc. But, if all you want to do is view a calibrated image and georeference it, there is a much easier and faster way: doing it yourself in Python.</p>
<p>You will need to install <a title="Python" href="http://www.python.org/" target="_blank">Python</a> (I am currently using Python 2.6 with IDLE on Mac OS 10.6), OSGEO&#8217;s <a title="GDAL" href="http://www.gdal.org/" target="_blank">GDAL</a>, and <a title="Numpy" href="http://numpy.scipy.org/" target="_blank">Numpy</a>. The first step is to import the modules:</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">import</span> numpy<br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">math</span><br />
<span style="color: #ff7700;font-weight:bold;">from</span> osgeo <span style="color: #ff7700;font-weight:bold;">import</span> gdal, GDT_Float32</div></div>
<p>Next we need to use GDAL to read the product.xml file with a sigma nought calibration (this will use the sigma lookup table) and set a few variables for later.</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">dataset = gdal.<span style="color: black;">Open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;RADARSAT_2_CALIB:SIGMA0:&quot;</span> + path + <span style="color: #483d8b;">&quot;product.xml&quot;</span><span style="color: black;">&#41;</span><br />
geotransform = dataset.<span style="color: black;">GetGeoTransform</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
gcps = dataset.<span style="color: black;">GetGCPs</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
gcpproj = dataset.<span style="color: black;">GetGCPProjection</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></div>
<p>The &#8220;path&#8221; variable is set by the user at the beginning of the script. Next, we need to read those GDAL objects into Numpy arrays in scattering (Sinclair) matrix format. Less memory is required for more complex processing tasks if we keep the matrix elements in separate matrices:</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">S_HH = dataset.<span style="color: black;">GetRasterBand</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>.<span style="color: black;">ReadAsArray</span><span style="color: black;">&#40;</span>xoff, yoff, xdim, ydim<span style="color: black;">&#41;</span><br />
S_HV = dataset.<span style="color: black;">GetRasterBand</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span>.<span style="color: black;">ReadAsArray</span><span style="color: black;">&#40;</span>xoff, yoff, xdim, ydim<span style="color: black;">&#41;</span><br />
S_VH = dataset.<span style="color: black;">GetRasterBand</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span>.<span style="color: black;">ReadAsArray</span><span style="color: black;">&#40;</span>xoff, yoff, xdim, ydim<span style="color: black;">&#41;</span><br />
S_VV = dataset.<span style="color: black;">GetRasterBand</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>.<span style="color: black;">ReadAsArray</span><span style="color: black;">&#40;</span>xoff, yoff, xdim, ydim<span style="color: black;">&#41;</span></div></div>
<p>The xoff, yoff, xdim and ydim variables refer to the offsets and dimensions. For example, you could analyze only a subset of the image. Now that we have the information in memory, we can generate an RBG using |HH|, |HV| and |VV| with GDAL:</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">r = numpy.<span style="color: black;">absolute</span><span style="color: black;">&#40;</span>S_HH<span style="color: black;">&#41;</span><br />
g = <span style="color: #ff4500;">2</span> <span style="color: #66cc66;">*</span> numpy.<span style="color: black;">absolute</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>S_HV + S_VH<span style="color: black;">&#41;</span>/<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span><br />
b = numpy.<span style="color: black;">absolute</span><span style="color: black;">&#40;</span>S_VV<span style="color: black;">&#41;</span><br />
driver = gdal.<span style="color: black;">GetDriverByName</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'GTiff'</span><span style="color: black;">&#41;</span><br />
output_dataset = driver.<span style="color: black;">Create</span><span style="color: black;">&#40;</span>path + filename, xdim, ydim, <span style="color: #ff4500;">3</span>, GDT_Float32, <span style="color: black;">&#91;</span><span style="color: #483d8b;">'PHOTOMETRIC=RGB'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
output_dataset.<span style="color: black;">SetGeoTransform</span><span style="color: black;">&#40;</span>geotransform<span style="color: black;">&#41;</span><br />
output_dataset.<span style="color: black;">SetGCPs</span><span style="color: black;">&#40;</span>gcps, gcpproj<span style="color: black;">&#41;</span><br />
output_dataset.<span style="color: black;">GetRasterBand</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>.<span style="color: black;">WriteArray</span><span style="color: black;">&#40;</span>r, <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span><br />
output_dataset.<span style="color: black;">GetRasterBand</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>.<span style="color: black;">WriteArray</span><span style="color: black;">&#40;</span>g, <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span><br />
output_dataset.<span style="color: black;">GetRasterBand</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span>.<span style="color: black;">WriteArray</span><span style="color: black;">&#40;</span>b, <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span><br />
output_dataset = <span style="color: #008000;">None</span></div></div>
<p>This creates a 3-band 32-bit float RGB GeoTiff.</p>
<p>If you need some sample imagery to play around with, try the <a title="RADARSAT-2 demo dataset" href="http://www.radarsat2.info/product/demo_set/" target="_blank">RADARSAT-2 demo dataset</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://benjamindeschamps.ca/blog/2009/11/12/processing-radarsat-2-imagery-reading-raw-data-and-saving-rgb-composites/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

