Posts archived in Software

0 comments

GIMP 2.8

GIMP is an open source image editing program. You can use it for a lot of the same things Adobe Photoshop is used for.

They just released version 2.8 (release notes).

In addition to GIMP, be sure to keep up with Inkscape, an open source vector graphics/illustration program. You might be able to do without Adobe Illustrator better than you think.

You can even typeset math equations using TeX. (link)

Both GIMP and Inkscape are available for Windows, Mac OSX, and Linux.

Writing a first draft is almost a completely different sport compared to editing and revising. It’s the most creative part of the writing effort. The work flow incorporates outlines, research notes, references, organization, re-organization, and more. I’ve recently been trying out a new program for writing first drafts: Scrivener.

Scrivener (Win and OSX) is a program designed to seemlessly combine word processing with several other writing tools including note organization, outlining, equation editing, and layout. It can work with EndNote (youtube), too.

It’s great to have all of these other tools right at hand and integrated. There’s less task-switching time.

The only shortcoming I can see is the lack of a “Track Changes” function like Word has. So it’s not great for collaboration, but it might reduce the time until the first draft gets done by reducing the time it takes to refer back to notes and other materials.

By virtue of their small eyes, mice enjoy a large depth of field. In a classic experiment (buried in the methods section) Balkema and Pinto put +6, 0, and -7 diopter lenses in front of mouse eyes and measured no change in retinal ganglion cell receptive field sizes. Clearly there isn’t much of a need for accomodation with such depth of field, and indeed, an attempt to stain for ciliary accomodation muscles in mouse eyes came up with zip (ref). Therefore, visual stimuli can be placed over a large range of distances in front of mice and remain in focus.

Since everything is in focus, it’s possible to place a visual stimulus monitor right in front of a mouse and cover a large amount of visual space. However, since the monitor is flat rather than spherical, the image will appear distorted from the mouse’s point of view. For example, a circle with a 100-pixel diameter in the middle of the screen will look larger and more circular than a 100-pixel diameter circle at the top left of the screen.

It’s related to a simple fisheye lens distortion, like the photograph above, but a bit more complex since the monitor is tilted towards the animal. So we can’t apply a simple pincushion distortion (which is the inverse of a fisheye distortion) to correct for it. I’ve found that a straightforward approach is to simply model the monitor. At first, I thought this would be rather inelegant, but in practice, it’s very simple.

Here I offer some MATLAB code that applies a corrective distortion to visual stimuli to cancel out the distortion caused by using a flat monitor to cover a large range of visual angle. With this code, you can treat the X-Y coordinates of a source image as angles of azimuth and elevation. The corrective distortion will change the image so that horizontal lines are mapped to isoelevation lines and vertical lines are mapped to isoazimuth lines.

Step one is to generate a 3D model of the monitor using some measurements that are easy to take. In the image below, on the left we have mapped pixel locations on the monitor in Cartesian coordinates relative to the mouse’s eye. On the right, we have re-mapped these to spherical coordinates. Using this data, we will generate an interpolation that applies the distortion.

Step two is to apply the distortion using interpolation. Here are a couple of example corrective distortions. On the left is the source image, on the right is the image after the corrective distortion. The curved lines will look straight from the mouse’s point of view.

By the way, using similar code, you can check and see how the visual stimuli would appear to the mouse if it went uncorrected. Here are a couple of examples.

More Labrigger posts on visual stimuli

Click through to get the MATLAB code….
Read the rest of this entry »

This is an iOS/iPhone app that uses the camera to optically recognize resistor color code bands. I find this interesting because I tried writing something like this one time. I couldn’t sleep at 3am after a London-Tokyo flight. I wanted to make an augmented reality app that would let the user scan the camera over a bunch of resistors or a circuit and the resistor values would be overlaid on each one. About 5 minutes into coding, I realized that it’s a significant image segmentation problem, with a non-trivial color recognition problem given different white balances, contrasts, and colors of paint. That wasn’t going to help me sleep.

The author of Resistor Photo ID simply makes the user take photographs in a stereotyped way with particular kind of background, thus limiting the variability. The program also makes the user do the image segmentation by dragging little ROIs to cover the color bands. These are clever compromises, and in the final analysis, it works. Not without errors, but it works.

Yes, you’re right, it takes almost no time to simply measure a resistor using a multimeter. You’re very clever. But what if the resistor is already in a circuit, and thus cannot be measured in isolation? Yes, yes, like you, I also enjoy the mild, learned synesthesia that comes with internalizing the resistor color code. But what if, like this author, you’re colorblind?

Colorblind-proof two-color scheme for co-localization
Daltonize your figures for the colorblind audience members

Nature just published a 4-page perspective article on the important of releasing the source code for programs used in scientific research. The authors emphasize the importance of reproducibility for results that depend on computation.

Labrigger has already covered releasing source code here, including the sympathetic CRAPL. In that license, it is acknowledged that the code offered is not pretty and no promise of support is offered (in fact, quite the opposite is promised). These are among the key concerns about releasing code. Perhaps the software relies on expensive, propriatery hardware and/or software. Perhaps the code is buggy as hell, thread hostile, devoid of error handling, and relies on core dumps as the main data output interface. Or perhaps the source code is poorly commented, or not commented at all, and all variable names are single characters. Perhaps the code is written in Whitespace with inline Brainfuck.

The authors spend a long time explaining that there is no substitute for releasing the source code. That is, pseudo code, mathematical, or natural language descriptions are never enough. Of course they’re right in principle, but I appreciate the alternative descriptions sometimes, so I wouldn’t want a source code release to replace those alternative descriptions. For example, I don’t want to have to sift through someone’s crap code just to find how they performed a specific bootstrap analysis. The description in the methods section should be sufficiently clear and detailed so that I can code it up myself.

One point the authors make is that errors can be detected when the entire source code is released. Sometimes, even commercial programs have bugs that change results. E.g., GraphPad had a rather unfortunate bug that resulted in data groups being flagged as significantly different when they weren’t.

The Open Microscopy Environment (OME) is a group of programmers, from academia and industry, who put together open source software packages for managing microscopy data. The emphasis is on handing multiple image formats, organizing them, displaying, and annoting them. Analysis is not an emphasis (though some basic measurements are possible), but the software can be useful as a front end to an image processing pipeline.

OpenElectrophy is a somewhat mature, actively developed, open source program for analyzing data from multielectrode recordings. It makes heavy use of Python and SQL and is developed by a team of French researchers including Samuel Garcia, Nicolas Fourcaud-Trocmé, Stéphane Gaétan Roux, and Christophe Pouzat.

It handles many file formats.

And has a rich set of tools for spike sorting.

Thorlabs and Newport have offered 3D models of their products for a long time. However, they’re typically in formats for expensive programs like SolidWorks and AutoCAD. In the past year or two, Newport has been slowly adding to their library of Google SketchUp models.

I still prefer SolidWorks, but I’m optimistic that I’ll eventually switch to SketchUp. Regardless, it’s nice to see a company supporting free tools.

0 comments

Competition

Like many of you, I went to monster truck show last weekend.

The competition reminded me MATLAB’s new thing: Cody.

It’s a bunch of problems posed as MATLAB coding tasks. For example:

Find the mean of each consecutive pair of numbers in the input row vector. For example,

x=[1 2 3] —-> y = [1.5 2.5]

x=[100 0 0 0 100] —-> y = [50 0 0 50]

To solve the problem, you write a MATLAB program that performs that input-output transformation. Of the correct answers, the shortest program wins. Answers are automatically checked for correctness and there is a graphic display of length and correctness of submitted answers:

At the very least, I think this is a clever tool for learning MATLAB. Working through exercises is pretty dry. This is effectively the same thing, but the competetion aspect is energizing. Most problems are locked until you solve easier ones. You can submit your own problems too. So this could be a sneaky way to crowd source your own work.

Long live competion.

In two previous posts I shared some MATLAB code to help design collection optics in 2p scopes.
Collection optics for 2p scopes, post 1
Collection optics for 2p scopes, post 2
It was just brought to my attention that I didn’t include the command locateVal in the code I posted. It’s a very simple little shortcut I use. Here it is:

function [pos difference] = locateVal(val,data)
[difference pos] = min(abs(data - val));


Yes, you could have guessed that. But I wanted to correct the oversight.