<?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>Codng &#187; Image Processing</title>
	<atom:link href="http://codng.com/category/image-processing/feed" rel="self" type="application/rss+xml" />
	<link>http://codng.com</link>
	<description>Nerd is the new cool.</description>
	<lastBuildDate>Wed, 02 Dec 2009 21:39:46 +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>Building 3D models using a Web Cam</title>
		<link>http://codng.com/building-3d-models-using-a-web-cam</link>
		<comments>http://codng.com/building-3d-models-using-a-web-cam#comments</comments>
		<pubDate>Wed, 25 Nov 2009 19:17:06 +0000</pubDate>
		<dc:creator>juancn</dc:creator>
				<category><![CDATA[Image Processing]]></category>
		<category><![CDATA[Microposts]]></category>
		<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://codng.com/?p=15</guid>
		<description><![CDATA[Incredible technology to build a 3D model from a video of the desired object. Just watch the video:

You can go to the project site for more details.
]]></description>
			<content:encoded><![CDATA[<p>Incredible technology to build a 3D model from a video of the desired object. Just watch the video:</p>
<p><object width="480" height="295"><param name="movie" value="http://www.youtube.com/v/vEOmzjImsVc&#038;hl=en_US&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/vEOmzjImsVc&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295"></embed></object></p>
<p>You can go to the <a href="http://mi.eng.cam.ac.uk/~qp202/my_papers/BMVC09/">project site</a> for more details.</p>
]]></content:encoded>
			<wfw:commentRss>http://codng.com/building-3d-models-using-a-web-cam/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Image Downscaling</title>
		<link>http://codng.com/image-downscaling</link>
		<comments>http://codng.com/image-downscaling#comments</comments>
		<pubDate>Fri, 02 Oct 2009 15:59:55 +0000</pubDate>
		<dc:creator>juancn</dc:creator>
				<category><![CDATA[Image Processing]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://codng.com/image-downscaling</guid>
		<description><![CDATA[A few days ago, a friend contacted me because he needed good image downscaling for a project he&#8217;s working on.
I remebered reading an article about the types of issues when downsampling an image (and specifically a difficult one). After a few tests, I settled for a gaussian pre-blur.
I think I got pretty good results:

Go to [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago, a friend contacted me because he needed good image downscaling for a project he&#8217;s working on.</p>
<p>I remebered reading <a href="http://www.xs4all.nl/~bvdwolf/main/foto/down_sample/down_sample.htm">an article</a> about the types of issues when downsampling an image (and specifically a difficult one). After a few tests, I settled for a gaussian pre-blur.</p>
<p>I think I got pretty good results:</p>
<p><a href='http://codng.com/wp-content/uploads/2009/10/downsampled.png' title='Downscaled image'><img src='http://codng.com/wp-content/uploads/2009/10/downsampled.png' alt='Downscaled image' /></a></p>
<p>Go to the <a href="http://www.xs4all.nl/~bvdwolf/main/foto/down_sample/down_sample.htm">original article</a> to get the source image.</p>
<p>The code also tries to fit and center the image in the target. That means it will return an image with the exact size you request. It will center and rescale the source image and leav transparent background for filler space.</p>
<pre class="brush: java;">
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.*;
import java.io.File;
import java.io.IOException;

public class FitImage {

    public static BufferedImage fitImage(final BufferedImage input, final int width, final int height) {
        final int inputWidth = input.getWidth();
        final int inputHeight = input.getHeight();

        final double hScale = width/(double)inputWidth;
        final double vScale = height/(double)inputHeight;

        final double scaleFactor = Math.min(hScale, vScale);

        //Create a temp image
        final BufferedImage temp = new BufferedImage(inputWidth,inputHeight, BufferedImage.TYPE_INT_ARGB);

        if(scaleFactor &lt; 1) {
            //Create a gaussian kernel with a raduis proportional to the scale factor and convolve it with the image
            final Kernel kernel = make2DKernel((float) (1 / scaleFactor));
            final BufferedImageOp op = new ConvolveOp(kernel);
            op.filter(input, temp);
        } else {
            temp.createGraphics().drawImage(input, null, 0,0);
        }

        final BufferedImage output = new BufferedImage(width,height, BufferedImage.TYPE_INT_ARGB);
        final Graphics2D g = output.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        final int xOffset = (int) Math.max(0, (width - inputWidth * scaleFactor) / 2);
        final int yOffset = (int) Math.max(0, (height - inputHeight * scaleFactor) / 2);
        final AffineTransform scaleInstance = AffineTransform.getScaleInstance(scaleFactor, scaleFactor);
        final AffineTransformOp transformOp = new AffineTransformOp(scaleInstance, AffineTransformOp.TYPE_BICUBIC);
        g.drawImage(temp, transformOp, xOffset, yOffset);
        return output;
    }

    public static Kernel make2DKernel(float radius) {
        final int r = (int)Math.ceil(radius);
        final int size = r*2+1;
        float standardDeviation = radius/3; //Guess a standard dev from the radius

        final float center = (float) (size/2);
        float sigmaSquared = standardDeviation * standardDeviation;

        final float[] coeffs = new float[size*size];

        for(int x = 0; x &lt; size; x++ ) {
            for(int y = 0; y &lt; size; y++ ) {
                double distFromCenterSquared = ( x - center ) * (x - center ) + ( y - center ) * ( y - center );
                double baseEexponential = Math.pow( Math.E, -distFromCenterSquared / ( 2.0f * sigmaSquared ) );
                coeffs[y*size+x]= (float) (baseEexponential / (2.0f*Math.PI*sigmaSquared ));
            }
        }

        return new Kernel(size, size, coeffs);
    }

    public static void main(String[] args)
            throws IOException
    {
        BufferedImage out = fitImage(ImageIO.read(new File(&quot;Rings1.gif&quot;)), 200, 200);
        ImageIO.write(out, &quot;png&quot;, new File(&quot;test.png&quot;));
    }

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://codng.com/image-downscaling/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
