www.pudn.com > jseg.rar > quan.c


#include 
#include 
#include 
#include 
#include "mathutil.h"
#include "imgutil.h"
#include "memutil.h"
#include "quan.h"
#include "ioutil.h"
#include "segment.h"

int quantize(float *B,float **cb,int nt,int ny,int nx,int dim,float thresh)
{
  int it,i,offset,N;
  float *A,*weight,avgweight;
  int ny2,nx2,ei;
  unsigned char *P;
int debug=0;

  ei = nt*ny*nx;
  printf ("color quantization\n");

  offset=2;
  ny2 = ny+2*offset; nx2 = nx+2*offset;
  weight=(float *)calloc(ei,sizeof(float));
  A=(float *)calloc(ny2*nx2*dim,sizeof(float));
  avgweight = 0;
  for (it=0;it256) N=256;
  N=greedy(B,ei,dim,N,cb,0.05,P,weight);

/* These codes are for testing direct VQ */
/*
  weight=(float *)calloc(ei,sizeof(float));
  for (i=0;i1)
  {
    if (mindist>=*thresh) 
    { 
      if (status==1) endloop=1; 
      else break;
    }
    total=count[mini]+count[minj];
    for (k=0;kmaxJ && mindist>thresh2) 
      {
        maxJ=oldJC-avgJC;
        if (olddistN) nsplit=N-in;
    for (jn=0;jn=d1) break;
        }
        if (d20.0)
      {
        for (k=0;k0)
        {
          j = iv*ndim;
          for (k=0;k0)
    {
      rate=(lastmse-mse)/lastmse;
      if (rate0)
    {
      for (k=0;k=0;j--)
      {
        if (difdif[j]>difdift) { J1=j+1; break; }
      }
      J2=winarea-1;
      for (j=winarea-1-nnoise;jdifdift) { J2=j; break; }
      }
      J=J2-2;

      if (distance2(A1[index[J1]],A1[index[J2]],dim)==0.0)
      {
        for (k=0;k