View Single Post
Old 11th November 2003, 09:14   #91  |  Link
General Lee D. Mented
Registered User
 
Join Date: Nov 2001
Posts: 92
Quote:
Originally posted by MfA
Filters 2-4 will access irrelevant values with the hilbert scan right?
2 and 4 should be irrelevant, as the vertical construction of the image is destroyed. However, I'd expect filters 1 and 3 to perform better. I tried enabling and disabling filters and even using none, but still always got bad results with the quadrant scan.

Here's a couple examples to play with if you like:

http://www.gldm.net/orig.png
http://www.gldm.net/quadrant.png

and the function, if anyone wants to play with that too:

Code:
void QuadrantScan(int** order, int hmin, int vmin, 
		 int hmax, int vmax, int size, int &current)
{

	int hmintemp, vmintemp, hmaxtemp, vmaxtemp;

	if (size == 1) // 1x1 array
		if(order[vmin][hmin] != 0)
		{
			order[vmin][hmin] = current;  // store order seen
			current++;
		}
		else
			; // don't store if marked out
	else{
		size /= 2;

		hmintemp = hmin;
		vmintemp = vmin;
		hmaxtemp = hmax - size;
		vmaxtemp = vmax - size;
		QuadrantScan(order, hmintemp, vmintemp,
			    hmaxtemp, vmaxtemp, size, current);

		hmintemp = hmin;
		vmintemp = vmin + size;
		hmaxtemp = hmax - size;
		vmaxtemp = vmax;
		QuadrantScan(order, hmintemp, vmintemp,
			    hmaxtemp, vmaxtemp, size, current);

		hmintemp = hmin + size;
		vmintemp = vmin + size;
		hmaxtemp = hmax;
		vmaxtemp = vmax;
		QuadrantScan(order, hmintemp, vmintemp,
			    hmaxtemp, vmaxtemp, size, current);

		hmintemp = hmin + size;
		vmintemp = vmin;
		hmaxtemp = hmax;
		vmaxtemp = vmax - size;
		QuadrantScan(order, hmintemp, vmintemp,
			    hmaxtemp, vmaxtemp, size, current);

	}

	return;
}
How to use it:
int** order is a 2D array of ints initialized to 1s used as a lookup table, to know what linear order a given 2D pixel falls in. Note that the array must be SQUARE and POWER of 2. Note int size is the length of the SIDE of the square array, not is entire area. If you need to handle cases with non-square areas or anything that doesn't fit perfect, load 1s in the area you plan to use, and 0s in the area you want masked out. For example, on a 512x512 array, if your image is 512x384, fill the first 384 lines with 1s, and the last 128 with 0s to generate a proper lookup table. This works for any pixel mask including random.

Once the table is made, forward transform looks like this:

destination[order[i][j]] = source[i][j];

reverse transform:

destination[i][j] = source[order[i][j]];

Note the 2D->1D translation by the table. If you want 2D->2D or some other combintation I'll leave the / and % conversion of 2D coordinates to and from a linear index for your own coding fun.
General Lee D. Mented is offline   Reply With Quote