Showing posts with label Processing. Show all posts
Showing posts with label Processing. Show all posts

June 30, 2014

ArsMatrix

ArsMatrix is a three-dimensional color anyalizing tool I Processing for Google's DevArt 2014. It's basically a 3D Histogram, altough a certain degree of artistic control is granted to the user regarding the look of the final 3D shape, and it's supposed to be more of a mesmerizing experience rather than a technical one.



From the project description:
ArsMatrix is a Processing Project aimed at becoming an interactive installation where people can explore and witness the properties of colors across multiple dimensions. ArsMatrix takes a 2-dimensional image and maps its color-information to a 3-dimensional Matrix, generating a 3D structure unique to each image.

The animated process and will show the 3D piece growing as the image is being scanned. The user will be able to change color balances and 3D visualization styles and see their changes in real time, hopefully coming to a higher understanding of color in what I hope to be a mesmerizing experience.

Images are picked randomly from the Google Picasa’s public feeds, either from the featured images album or using a word chosen by the user as a search bias. 

The project was awarded a weekly feature during the compatition. Thinking back on it, it wasn't really suited to be an interactive installation, but the idea at its base had been buzzing inside my head for a while, and the competition just gave me an excuse to start eveloping it seriously without caring too much about the rules and regulations... For more details / images / videos, check out the Github Page of the project.

March 29, 2014

Picasa APIs in Processing

During the development of my Goggle DevArt project, I was going to dive into the beautiful world of APIs to dynamically get some images to do cool stuff with. The definition of API is very broad, but in our case (crazy people getting stuff into Processing to get even crazie stuff out) an API is a a set of methods that allows us (or our beutiful app) to communicate with a website and let us use its services. Using the Picasa APIs in Processing allows your application to get images from the online Picasa albums or Google + photos, which is based on the Picasa platform, which can be useful in order to get random pictures if you are doing some image processing based work.

Using the Picasa APIs in Processing issimpler than you'd expect, since Processing can run pure Java we can implement most of the methods described in the Developer's Guide.  Before we start, however, we need to install a few libraries the APIs are dependant on:
To install a .jar in Processing, simply drag the .jar to the sketch - it will be added to the "code" folder of the project - afterwards, just import the libraries in your sketch. Then, you are ready to start your Picasa service.

PicasawebService myService = new PicasawebService("leon-picasaTest-1");
try {
baseSearchUrl = new URL("https://picasaweb.google.com/data/feed/api/all");
} 
catch (Exception e) {
println("Problem with the URL:" + e);
}
Query myQuery = new Query(baseSearchUrl);

A note here: Processing needs exception catching (telling it what to do in case of an error), or the code will not run. At this point, there are several ways to get the materials you want, whether you want to get the URL of a public image, an album, a particular tag. One is to change the URL you feed to the query, (like a GET request, for those familiars with it). There is some good reference about the feed codes here and here. Another way is to use change those parameters in the Query object, for example:

myQuery.setStringCustomParameter("kind", "photo");
  // max results to be returned
  myQuery.setMaxResults(8);
  // search parameters: in my case, "art"
  myQuery.setFullTextQuery("art");
The pictures are returned as PhotoEntry objects indide an array searchResultsFeed. We can easily go through them and get their URLs:
myQuery.setStringCustomParameter("kind", "photo");
try {
    searchResultsFeed = myService.query(myQuery, AlbumFeed.class);
  } 
  catch (Exception e) {
    println("Problem with the AlbumFeed: " + e);
  }

  for (PhotoEntry photo : searchResultsFeed.getPhotoEntries()) {
    // get the data out of the pictures
    println("Title: " + photo.getTitle().getPlainText());   
    println("URL: " + photo.getMediaThumbnails().get(0).getUrl());
}
The best thing about Picasa is that we can request the URL of an image for a particular size and aspect ratio, instead of doing the diry work ourself. A typical URL for a Picasa image looks like this:
https://lh4.googleusercontent.com/-8RYFTpzzwn4/UXCUe9tsSgI/AAAAAAAAo0M/eNLUAOorumc/s72/dinascrowcastle-2.JPG
Where "s720" is the part we want to look at: "s" means "size" and "72" refers to the size of the image in horizontal pixel - By default, images URLs are returned with this size. If we replace that with "s512", the image will be resize to a width of 512, keeping the aspect ration. Replacing it with "w512-h320" lets you change width and height separately, in this case we are resizing it to 512 pixels wide and 320 pixels high, while adding "-c" after it crops the image to a square format. We can easily change this in Processing using string replacements, and we are left with an URL we can use to load a PImage object.
myQuery.setStringCustomParameter("kind", "photo");
String imageUrl = photo.getMediaThumbnails().get(0).getUrl();
    String croppedUrl = imageUrl.replace("s72", "s220-c");
    println(croppedUrl);
    PImage pic = loadImage(croppedUrl);