Computing Feret diameters from the convex hull

February 13th, 2012

Some time ago I wrote about how to compute the Feret diameters of a 2D object based on the chain code of its boundary. The diameters we computed were the longest and shortest projections of the object. The shortest projection, or smallest Feret diameter, is equivalent to the size measured when physically passing objects through sieves (i.e. sieve analysis, as is often done, e.g., with rocks). The longest projection, or largest Feret diameter, is useful as an estimate of the length of elongated objects.

The algorithm I described then simply rotated the object in two-degree intervals, and computed the projection length at each orientation. The problem with this algorithm is that the width estimated for very elongated objects is not very accurate: the orientation that produces the shortest projection could be up to 1 degree away from the optimal orientation, meaning that the estimated width is length⋅sin(π/180) too large. This doesn’t sound like much, but if the aspect ratio is 100, meaning the length is 100 times the width, we can overestimate the width by up to 175%!

Read the rest of this entry »

DIPimage 2.4 released

January 12th, 2012

I’m pleased to announce that a new version of DIPimage has been released. There’s some performance improvements, some bug fixes, and some new functions. The measure function has some new features also, that use the convex hull of the objects. The Feret measure is computed differently now, also using the convex hull. This makes this computation more accurate and also somewhat faster.

But most importantly, we have rewritten a lot of the code that does binary arithmetic and logic operators. Binary here means these operators take two inputs. +, -, *, &, > and == are examples of binary operators. All of these used to be computed using MATLAB code, which required some nifty tricks. For example, computations between images of different type (i.e. an 8-bit integer image added to an 16-bit integer image) used to require data conversion because MATLAB cannot perform such a computation. All of these binary operators are now computed by DIPlib instead. This makes some cases much more efficient. We parallelized the arithmetic and logic code in DIPlib for further speed improvements.

Read the rest of this entry »

Scientific writing and the pronoun I

October 5th, 2011

Why are scientists so scared of writing their statements in the first person? Open any journal, and look for the word “I”. Chances are, you won’t find it. You’ll see article authors jump through hoops just to avoid this word. As if it were dirty, illegal. For example, instead of a normal, complete sentence like “I found existing methods to be insufficiently accurate,” you’ll find the sentence “Existing methods were found to be insufficiently accurate.” This leaves the most important thing out: who found them insufficiently accurate? Is this a generally known thing? Does the whole world share this opinion? Was it the dog that didn’t like the method? Why do they shy away from the word “I”? Does it make science less objective?

Read the rest of this entry »

The convex hull of a 2D object

September 18th, 2011

Last year I wrote about computing the the boundary length and various other measures, given an object’s chain code. The chain code is a simple way of encoding the polygon that represents a 2D object. It is very simple to compute the object’s convex hull given this polygon. Why would I want to do that? Well, the convex hull gives several interesting object properties, such as the convexity (object area divided by convex hull area). Certain other properties, such as the Feret diameters, are identical for an object and its convex hull, and the convex hull thus gives an efficient algorithm to compute these properties.

Read the rest of this entry »

Bresenham’s line drawing algorithm in any number of dimensions

July 22nd, 2011

edit: I should have called this “an algorithm that produces the same output as Bresenham’s algorithm, generalised to arbitrary dimensions” (see discussion below)

J.E. Bresenham published an algorithm in 1965, which is used to draw 2D digital lines. Many people have extended the algorithm to work in 3D, and I’ve even found a website with code for 4D, 5D and 6D versions of the algorithm. However, all the code I come across is way more complex that it needs to be, giving the impression that this is a complicated algorithm. Nothing is further from the truth! Drawing digital lines is the most simple and straight-forward task. I’m going to deviate from the classical thinking that an efficient algorithm should use only integer values. This will make our task trivial.

Read the rest of this entry »