KernelInfo updating

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
Danack
Posts: 73
Joined: 2013-10-14T10:00:25-07:00
Authentication code: 6789

KernelInfo updating

Post by Danack »

Hi,

When a KernelInfo struct has been created, and the values in the kernel are then modified, is it required that the values of

minimum, maximum, negative_range, positive_range, angle;

in the struct are updated by whoever modified the kernel or are they updated elsewhere?

Also, I can guess what minimum and maximum are; are the entries negative_range, positive_range, and angle described anywhere as to what they are meant to be?

cheers
Dan
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: KernelInfo updating

Post by snibgo »

I haven't done much programming with kernels, but it looks to me that if you want to create or modify your own, you should do the same work as morphology.c function ParseKernelArray() or CalcKernelMetaData().
snibgo's IM pages: im.snibgo.com
Danack
Posts: 73
Joined: 2013-10-14T10:00:25-07:00
Authentication code: 6789

Re: KernelInfo updating

Post by Danack »

Thanks, the CalcKernelMetaData looks like the right one to copy.

After looking at it, it seems that the angle value is only used for rotating the kernels. So as long as I don't want to use those, it should just be left to 0?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: KernelInfo updating

Post by snibgo »

I can't be certain (your guess is probably better than mine), but when modifying a kernel, I think you should not change angle.
snibgo's IM pages: im.snibgo.com
Danack
Posts: 73
Joined: 2013-10-14T10:00:25-07:00
Authentication code: 6789

Re: KernelInfo updating

Post by Danack »

btw it would be good if the code below from morphology.c was moved to it's own function where it could be reused. I think it's needed by anyone that wants to allow users to specify a string to create a Kernel.

Or possibly just the whole ParseKernelName() function.

Some documentations of how the values of GeometryInfo are used would also be awesome because:

double
rho,
sigma,
xi,
psi,
chi;

Just aren't that self-documenting.

Code: Select all


  /* special handling of missing values in input string */
  switch( type ) {
    /* Shape Kernel Defaults */
    case UnityKernel:
      if ( (flags & WidthValue) == 0 )
        args.rho = 1.0;    /* Default scale = 1.0, zero is valid */
      break;
    case SquareKernel:
    case DiamondKernel:
    case OctagonKernel:
    case DiskKernel:
    case PlusKernel:
    case CrossKernel:
      if ( (flags & HeightValue) == 0 )
        args.sigma = 1.0;    /* Default scale = 1.0, zero is valid */
      break;
    case RingKernel:
      if ( (flags & XValue) == 0 )
        args.xi = 1.0;       /* Default scale = 1.0, zero is valid */
      break;
    case RectangleKernel:    /* Rectangle - set size defaults */
      if ( (flags & WidthValue) == 0 ) /* if no width then */
        args.rho = args.sigma;         /* then  width = height */
      if ( args.rho < 1.0 )            /* if width too small */
          args.rho = 3;                /* then  width = 3 */
      if ( args.sigma < 1.0 )          /* if height too small */
        args.sigma = args.rho;         /* then  height = width */
      if ( (flags & XValue) == 0 )     /* center offset if not defined */
        args.xi = (double)(((ssize_t)args.rho-1)/2);
      if ( (flags & YValue) == 0 )
        args.psi = (double)(((ssize_t)args.sigma-1)/2);
      break;
    /* Distance Kernel Defaults */
    case ChebyshevKernel:
    case ManhattanKernel:
    case OctagonalKernel:
    case EuclideanKernel:
      if ( (flags & HeightValue) == 0 )           /* no distance scale */
        args.sigma = 100.0;                       /* default distance scaling */
      else if ( (flags & AspectValue ) != 0 )     /* '!' flag */
        args.sigma = QuantumRange/(args.sigma+1); /* maximum pixel distance */
      else if ( (flags & PercentValue ) != 0 )    /* '%' flag */
        args.sigma *= QuantumRange/100.0;         /* percentage of color range */
      break;
    default:
      break;
  }


Post Reply