Images
Vector Magic
2007-12-15

Vector Magic is a web service at Stanford University that converts bit-mapped images into vector-images. Here is a rendering of an EPS generated by the service that was originally a photograph:

A close-up of the nose:

And here is the original photo:

To use the service, go to http://vectormagic.stanford.edu/ and upload an image of some sort. Answer the questions, make some color selections, and the computers do their stuff. The processing for the image I uploaded took about five seconds. Once the vectorization is complete you are given the opportunity to reprocess or edit the image before downloading it:

I can see this being very useful for creating new scalable artwork out of old bit-mapped logos and graphics. For photos it has a somewhat limited appeal, but could be used for artistic effect that goes beyond simple posterization.
|
Content-Aware Image Resizing
2007-08-23
This has to be seen to be believed. It's an image resizing technique that can convert an image while retaining features at the same size. For example this image:

Was resized from this one:

It looks like a scaling, until you see the rock in the sea, the waterfall, and the rock that sticks up in the center. Here is an intermediate resizing between the two above:


Was resized from this one:

It looks like a scaling, until you see the rock in the sea, the waterfall, and the rock that sticks up in the center. Here is an intermediate resizing between the two above:

Aperture Plugin: Generating The Random Name and Renaming Images
2007-03-16

Now I am able to generate the random string I can rename the images after they have been exported. So for each image file I do this:

To get the image UUID, depending on the API version I call either a method that gets the image properties with or without the thumbnail. I don't need the thumbnail, so I prefer to use the one that uses least memory. To determine which API to use, I add this code to the -initiWithAPIManager method:

To generate the random string I either use the salt string or not, depending on whether the checkbox is set. Then the random string is combined with the other parts of the name and used for the rename (achieved with the movePath:toPath:handler method). I add hyphens to the name in the code above for debug purposes. In real life the format string will drop the hyphens.
This code is not very memory-friendly. Each time around the loop will allocate more memory, so I need to refactor it with better memory use.
There. Finally making random file names!
The other parts of this series can be found via the Cocoa page.
Aperture Plugin: Saving The Image Files
2007-02-04

Since my code just logs file names so far, the next thing I am going to do is change it so that it actually saves the data to disk. Initially I am going to save the files without using any randomization. Later I will implement the random naming.
The full path name to use comprises the name that I was given by -exportManagerWillbeginExportToPath: (and saved in _exportBasePath) with the file name given in the path variable in -exportManagerShouldWriteImageData:relativeToPath:forImageAtIndex:

And this works. I'm using the file names given to me by Aperture which means either the master file name or the version name depending on the user's selection on the dialog.
After some experimentation I discovered that Aperture always gives the plug-in a filename that can be written successfully. If a file already exists with the name of the image to be written, Aperture appends (1) or (2), etc. to the end of the name and gives that to the plug-in. So instead of trying to handle all the cases that Aperture is already handling for me regarding the naming, the strategy for generating random names should be to let Aperture do all the file writing with its own names and then rename the files myself when it is done. This actually makes randomizing the names easier because I will be in possession of all the information about all the files at the same time and won't have to maintain any state between naming image files.
To rename all the files at once I will have to make a copy of all the paths as I am given them. Once the exports are all done, I will generate a list of random names, and then use NSFilemanager -movePath:toPath:handler: to do the rename.
To store the names I create an NSMutableArray called _origFileNames and initialize it in the initWithAPIManager: method. Then in -exportManagerShouldWiteImageData: I add each file name to the array:
And in -exportManagerDidFinishExport I iterate through the stored filenames and do the rename:

For now I am just using a sequence of numbers 0001, 0002, etc. And I am being careful to keep the same file extension. My code is a little sloppy here with memory usage (what if this code is run with a huge number of files?) and I am not checking a lot of possible error conditions, such as existing files with the same numbered names. I will have to tackle problems like that when I write my final randomizing code.
The other parts of this series can be found via the Cocoa page.
The Bagelturf site welcomes Donations of any size