/* * bin_search_StepSize: * -------------------- * Succesive approximation approach to obtaining a initial quantizer * step size. * The following optional code written by Seymour Shlien * will speed up the shine_outer_loop code which is called * by iteration_loop. When BIN_SEARCH is defined, the * shine_outer_loop function precedes the call to the function shine_inner_loop * with a call to bin_search gain defined below, which * returns a good starting quantizerStepSize. */ int bin_search_StepSize(int desired_rate, int ix[GRANULE_SIZE], gr_info * cod_info, shine_global_config *config) { int bit, next, count; next = -120; count = 120; do { int half = count / 2; if (quantize(ix, next + half, config) > 8192) bit = 100000; /* fail */ else { calc_runlen(ix, cod_info); /* rzero,count1,big_values */ bit = count1_bitcount(ix, cod_info); /* count1_table selection */ subdivide(cod_info, config); /* bigvalues sfb division */ bigv_tab_select(ix, cod_info); /* codebook selection */ bit += bigv_bitcount(ix, cod_info); /* bit count */ } if (bit < desired_rate) count = half; else { next += half; count -= half; } } while (count > 1); return next; }
/* Color-Cartoon Filter Imaplementation */ void colorCartoonFilter(Mat& src, Mat& dst, int edgeThickness, int edgeThreshold) { // denormalize params edgeThickness = (edgeThickness*(CARTOON_THICK_MAX - CARTOON_THICK_MIN))/INPUT_MAX + CARTOON_THICK_MIN; if(edgeThickness%2 == 0) edgeThickness++; edgeThreshold = (edgeThreshold*(CARTOON_THRESH_MAX - CARTOON_THRESH_MIN))/INPUT_MAX + CARTOON_THRESH_MIN; Mat src_blurred, src_gray, quantized, edges; // Denoise image GaussianBlur(src, src_blurred, Size(5,5), 0); // Get src image grayscale cvtColor(src_blurred, src_gray, CV_RGBA2GRAY); // Quantize gray img to get discrete shades quantize(src_gray, quantized); cvtColor(quantized, dst, CV_GRAY2RGBA); // superimpose gray shades on color src img //subtract(src_blurred, ~dst, dst); add(0.7*src_blurred,0.7*dst,dst); // get illumination-resistant edges by adaptive thresholding adaptiveThreshold(src_gray, src_gray, 255, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY, edgeThickness, edgeThreshold); cvtColor(src_gray, edges, CV_GRAY2RGBA); // superimpose edges on shaded src img subtract(dst, ~edges, dst); }
/* * bin_search_StepSize: * -------------------- * Succesive approximation approach to obtaining a initial quantizer * step size. * The following optional code written by Seymour Shlien * will speed up the outer_loop code which is called * by iteration_loop. When BIN_SEARCH is defined, the * outer_loop function precedes the call to the function inner_loop * with a call to bin_search gain defined below, which * returns a good starting quantizerStepSize. */ int bin_search_StepSize(int desired_rate, int ix[samp_per_frame2], gr_info * cod_info) { int top,bot,next,last,bit; top = -120; bot = 0; next = top; do { last = next; next = (top+bot) >> 1; if(quantize(ix,next) > 8192) bit = 100000; /* fail */ else { calc_runlen(ix,cod_info); /* rzero,count1,big_values */ bit = count1_bitcount(ix, cod_info); /* count1_table selection */ subdivide(cod_info); /* bigvalues sfb division */ bigv_tab_select(ix,cod_info); /* codebook selection */ bit += bigv_bitcount(ix,cod_info); /* bit count */ } if (bit>desired_rate) top = next; else bot = next; } while((bit!=desired_rate) && abs(last-next)>1); return next; }
void ANT_ranking_function_DPH::relevance_rank_top_k(ANT_search_engine_result *accumulator, ANT_search_engine_btree_leaf *term_details, ANT_compressable_integer *impact_ordering, long long trim_point, double prescalar, double postscalar, double query_frequency) { long long docid; double f, norm, tf, cf, score; ANT_compressable_integer *current, *end; current = impact_ordering; end = impact_ordering + (term_details->local_document_frequency >= trim_point ? trim_point : term_details->local_document_frequency); cf = (double)term_details->global_collection_frequency; while (current < end) { end += 2; // account for the impact_order and the terminator tf = *current++ * prescalar; docid = -1; while (*current != 0) { docid += *current++; f = tf / document_lengths[(size_t)docid]; norm = (1.0 - f) * (1.0 - f) / (tf + 1.0); score = 1.0 * norm * (tf * ANT_log2((tf * mean_document_length / document_lengths[(size_t)docid]) * (documents / cf)) + 0.5 * ANT_log2(2.0 * M_PI * tf * (1.0 - f))); accumulator->add_rsv(docid, quantize(postscalar * score, maximum_collection_rsv, minimum_collection_rsv)); } current++; // skip over the zero } }
int lsx_process_threaded_noninterleaved(lsx_thread_state_t *state, const float * const *ibuf, float **obuf, size_t *ilen, size_t *olen, size_t istride, size_t ostride) { int n; size_t i; size_t count = ilen ? min(*ilen, IO_BUFSIZE) : 0; for (n = 0; n < state->count; ++n) { state->pth[n].ilen = count; state->pth[n].olen = min(*olen, IO_BUFSIZE); } for (n = 0; n < state->count; ++n) for (i = 0; i < count; ++i) state->pth[n].ibuf[i] = ibuf[n][i * istride]; if (run_filter(state) < 0) return -1; for (n = 0; n < state->count; ++n) for (i = 0; i < state->pth[0].olen; ++i) obuf[n][i * ostride] = quantize(state->pth[n].obuf[i]); if (ilen && *ilen) *ilen = state->pth[0].ilen; *olen = state->pth[0].olen; return 0; }
void PianorollTrackView::handleMouseLeftButtonPressByPencil(QMouseEvent *event) { const VSQ_NS::Event *noteEventOnMouse = findNoteEventAt(event->pos()); if (noteEventOnMouse) { initMouseStatus(MouseStatus::LEFTBUTTON_MOVE_ITEM, event, noteEventOnMouse); ItemSelectionManager *manager = controllerAdapter->getItemSelectionManager(); if ((event->modifiers() & Qt::ControlModifier) != Qt::ControlModifier) { manager->clear(); } manager->add(noteEventOnMouse); updateWidget(); } else { ItemSelectionManager *manager = controllerAdapter->getItemSelectionManager(); bool repaint = false; if (!manager->getEventItemList()->empty()) { manager->clear(); repaint = true; } initMouseStatus(MouseStatus::LEFTBUTTON_ADD_ITEM, event, noteEventOnMouse); QPoint mousePosition = mapToScene(event->pos()); int note = getNoteNumberFromY(mousePosition.y(), trackHeight); VSQ_NS::tick_t clock = controllerAdapter->getTickFromX(mousePosition.x()); clock = quantize(clock); mouseStatus.addingNoteItem = VSQ_NS::Event(clock, VSQ_NS::EventType::NOTE); mouseStatus.addingNoteItem.note = note; hideLyricEdit(); if (repaint) updateWidget(); } }
const void * _from_float (const float *src, T *dst, size_t nvals, long long quant_min, long long quant_max) { if (! src) { // If no source pixels, assume zeroes T z = T(0); for (size_t p = 0; p < nvals; ++p) dst[p] = z; } else if (std::numeric_limits <T>::is_integer) { // Convert float to non-float native format, with quantization for (size_t p = 0; p < nvals; ++p) dst[p] = (T) quantize (src[p], quant_min, quant_max); } else { // It's a floating-point type of some kind -- we don't apply // quantization if (sizeof(T) == sizeof(float)) { // It's already float -- return the source itself return src; } // Otherwise, it's converting between two fp types for (size_t p = 0; p < nvals; ++p) dst[p] = (T) src[p]; } return dst; }
int DjVuPalette::compute_palette_and_quantize(GPixmap &pm, int maxcolors, int minboxsize) { int result = compute_pixmap_palette(pm, maxcolors, minboxsize); quantize(pm); return result; }
/* * g721_encoder() * * Encodes the input vale of linear PCM, A-law or u-law data sl and returns * the resulting code. -1 is returned for unknown input coding value. */ int g721_encoder( int sl, G72x_STATE *state_ptr) { short sezi, se, sez; /* ACCUM */ short d; /* SUBTA */ short sr; /* ADDB */ short y; /* MIX */ short dqsez; /* ADDC */ short dq, i; /* linearize input sample to 14-bit PCM */ sl >>= 2; /* 14-bit dynamic range */ sezi = predictor_zero(state_ptr); sez = sezi >> 1; se = (sezi + predictor_pole(state_ptr)) >> 1; /* estimated signal */ d = sl - se; /* estimation difference */ /* quantize the prediction difference */ y = step_size(state_ptr); /* quantizer step size */ i = quantize(d, y, qtab_721, 7); /* i = ADPCM code */ dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized est diff */ sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconst. signal */ dqsez = sr + sez - se; /* pole prediction diff. */ update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr); return (i); }
bool KMeansQuantizer::computeFeatures(const VectorFloat &inputVector){ //Run the quantize algorithm quantize( inputVector ); return true; }
int main(int argc, char **argv) { FILE *files[64]; int numFiles = 0; for(int i = 2; i < argc; i++){ files[numFiles] = fopen(argv[i], "r"); numFiles++; } if(argv[1][0] == 'q'){ fvec centroids[3]; fvec variances; quantize(numFiles, files, 3, centroids, variances); cout<<variances(0); for(int i = 1; i < F0_FEATURES; i++) cout<<","<<variances(i); cout<<endl; for(int j = 0; j < 3; j++){ cout<<centroids[j](0); for(int i = 1; i < F0_FEATURES; i++) cout<<","<<centroids[j](i); cout<<endl; } } else if(argv[1][0] == 't'){ cout<<"decided on "<<test(files[0], numFiles - 1, &files[1])<<endl; } for(int i = 0; i < numFiles; i++) fclose(files[i]); }
int main() { tga_image tga; double dct_buf[8][8]; int i, j, k, l; load_tga(&tga, "in.tga"); k = 0; l = (tga.height / 8) * (tga.width / 8); for (j=0; j<tga.height/8; j++) for (i=0; i<tga.width/8; i++) { dct(&tga, dct_buf, i*8, j*8); quantize(dct_buf); idct(&tga, dct_buf, i*8, j*8); printf("processed %d/%d blocks.\r", ++k,l); fflush(stdout); } printf("\n"); DONTFAIL( tga_write_mono("out.tga", tga.image_data, tga.width, tga.height) ); tga_free_buffers(&tga); return EXIT_SUCCESS; }
void DisplayManager::writeTile(V2i pos, const float* data) { int nPixels = prod(m_tileSize); for(int idisp = 0; idisp < (int)m_displayInfo.size(); ++idisp) { DisplayData& dispInfo = m_displayInfo[idisp]; int nChans = dispInfo.var.scalarSize(); ConstFvecView src(data + dispInfo.var.offset, nChans, m_totChans); if(dispInfo.quantize) { // Quantize into temporary buffer uint8* tmpTile = static_cast<uint8*>( tmpStorage(nChans*nPixels*sizeof(uint8))); quantize(src, prod(m_tileSize), tmpTile); LockGuard lk(m_mutex); dispInfo.display->writeTile(pos, tmpTile); } else { // Copy over channels directly. float* tmpTile = static_cast<float*>( tmpStorage(nChans*nPixels*sizeof(float))); copy(FvecView(tmpTile, nChans), src, nPixels); LockGuard lk(m_mutex); dispInfo.display->writeTile(pos, tmpTile); } } }
/* ANT_RANKING_FUNCTION_DPH::RELEVANCE_RANK_TOP_K() ------------------------------------------------ */ void ANT_ranking_function_DPH::relevance_rank_top_k(ANT_search_engine_result *accumulator, ANT_search_engine_btree_leaf *term_details, ANT_impact_header *impact_header, ANT_compressable_integer *impact_ordering, long long trim_point, double prescalar, double postscalar, double query_frequency) { long long docid; double f, norm, tf, cf, score; ANT_compressable_integer *current, *end; cf = (double)term_details->global_collection_frequency; impact_header->impact_value_ptr = impact_header->impact_value_start; impact_header->doc_count_ptr = impact_header->doc_count_start; current = impact_ordering; while (impact_header->doc_count_ptr < impact_header->doc_count_trim_ptr) { tf = *impact_header->impact_value_ptr * prescalar; docid = -1; end = current + *impact_header->doc_count_ptr; while (current < end) { docid += *current++; f = tf / document_lengths[(size_t)docid]; norm = (1.0 - f) * (1.0 - f) / (tf + 1.0); score = 1.0 * norm * (tf * ANT_log2((tf * mean_document_length / document_lengths[(size_t)docid]) * (documents / cf)) + 0.5 * ANT_log2(2.0 * M_PI * tf * (1.0 - f))); accumulator->add_rsv(docid, quantize(postscalar * score, maximum_collection_rsv, minimum_collection_rsv)); } current = end; impact_header->impact_value_ptr++; impact_header->doc_count_ptr++; } #pragma ANT_PRAGMA_UNUSED_PARAMETER }
/* * g723_40_encoder() * * Encodes a 16-bit linear PCM, A-law or u-law input sample and retuens * the resulting 5-bit CCITT G.723 40Kbps code. * Returns -1 if the input coding value is invalid. */ int g723_40_encoder (int sl, G72x_STATE *state_ptr) { short sei, sezi, se, sez; /* ACCUM */ short d; /* SUBTA */ short y; /* MIX */ short sr; /* ADDB */ short dqsez; /* ADDC */ short dq, i; /* linearize input sample to 14-bit PCM */ sl >>= 2; /* sl of 14-bit dynamic range */ sezi = predictor_zero(state_ptr); sez = sezi >> 1; sei = sezi + predictor_pole(state_ptr); se = sei >> 1; /* se = estimated signal */ d = sl - se; /* d = estimation difference */ /* quantize prediction difference */ y = step_size(state_ptr); /* adaptive quantizer step size */ i = quantize(d, y, qtab_723_40, 15); /* i = ADPCM code */ dq = reconstruct(i & 0x10, _dqlntab[i], y); /* quantized diff */ sr = (dq < 0) ? se - (dq & 0x7FFF) : se + dq; /* reconstructed signal */ dqsez = sr + sez - se; /* dqsez = pole prediction diff. */ update(5, y, _witab[i], _fitab[i], dq, sr, dqsez, state_ptr); return (i); }
/****************************************************************************** ** huffman_encode ** -------------------------------------------------------------------------- ** Quantize and Encode a 8x8 DCT block by JPEG Huffman lossless coding. ** This function writes encoded bit-stream into bit-buffer. ** ** ARGUMENTS: ** ctx - pointer to encoder context; ** data - pointer to 8x8 DCT block; ** ** RETURN: - ******************************************************************************/ void huffman_encode(huffman_t *const ctx, const short data[], unsigned block_num) { unsigned magn, bits; unsigned zerorun, i; short diff; short dc = quantize(data[0], ctx->qtable[0]); // WARNING: in order to everything to work correctly // the get_DC_value must be called before the block_start // otherwise it returns a wrong DC value in case of megablocks // (the block_start reset the force_marker variable, which is // used by get_DC_value diff = get_DC_value(dc, block_num); block_start(block_num); bits = huffman_bits(diff); magn = huffman_magnitude(diff); add_to_block(ctx->hdcbit[magn], ctx->hdclen[magn]); add_to_block(bits, magn); for (zerorun = 0, i = 1; i < 64; i++) { const short ac = quantize(data[zig[i]], ctx->qtable[zig[i]]); if (ac) { while (zerorun >= 16) { zerorun -= 16; // ZRL add_to_block(ctx->hacbit[15][0], ctx->haclen[15][0]); } bits = huffman_bits(ac); magn = huffman_magnitude(ac); add_to_block(ctx->hacbit[zerorun][magn], ctx->haclen[zerorun][magn]); add_to_block(bits, magn); zerorun = 0; } else zerorun++; } if (zerorun) { // EOB - End Of Block add_to_block(ctx->hacbit[0][0], ctx->haclen[0][0]); } block_end(&bitbuf); }
void PianorollTrackView::onMouseMoveSlot(QMouseEvent *event) { if (mouseStatus.mode == MouseStatus::LEFTBUTTON_SELECT_ITEM) { mouseStatus.endPosition = mapToScene(event->pos()); updateSelectedItem(); updateWidget(); } else if (mouseStatus.mode == MouseStatus::MIDDLEBUTTON_SCROLL) { QPoint globalMousePos = ui->mainContent->mapToGlobal(event->pos()); int deltaX = globalMousePos.x() - mouseStatus.globalStartPosition.x(); int deltaY = globalMousePos.y() - mouseStatus.globalStartPosition.y(); ui->mainContent->horizontalScrollBar() ->setValue(mouseStatus.horizontalScrollStartValue - deltaX); ui->mainContent->verticalScrollBar() ->setValue(mouseStatus.verticalScrollStartValue - deltaY); updateWidget(); } else if (mouseStatus.mode == MouseStatus::LEFTBUTTON_MOVE_ITEM) { QPoint currentMousePos = mapToScene(event->pos()); // マウスの移動量から、クロック・ノートの移動量を算出 VSQ_NS::tick_t deltaClocks = controllerAdapter->getTickFromX(currentMousePos.x()) - controllerAdapter->getTickFromX(mouseStatus.startPosition.x()); if (mouseStatus.noteOnMouse) { VSQ_NS::tick_t editedNoteClock = quantize(mouseStatus.noteOnMouse->clock + deltaClocks); deltaClocks = editedNoteClock - mouseStatus.noteOnMouse->clock; } int deltaNoteNumbers = getNoteNumberFromY(currentMousePos.y(), trackHeight) - getNoteNumberFromY(mouseStatus.startPosition.y(), trackHeight); // 選択されたアイテムすべてについて、移動を適用する ItemSelectionManager *manager = controllerAdapter->getItemSelectionManager(); manager->moveItems(deltaClocks, deltaNoteNumbers); updateWidget(); } else if (mouseStatus.mode == MouseStatus::LEFTBUTTON_ADD_ITEM) { QPoint currentMousePos = mapToScene(event->pos()); VSQ_NS::tick_t endClock = controllerAdapter->getTickFromX(currentMousePos.x()); VSQ_NS::tick_t length = 0; if (mouseStatus.addingNoteItem.clock < endClock) { length = endClock - mouseStatus.addingNoteItem.clock; length = quantize(length); } mouseStatus.addingNoteItem.setLength(length); updateWidget(); } mouseStatus.isMouseMoved = true; }
/* ANT_RANKING_FUNCTION_PUURULA_IDF::RELEVANCE_RANK_TOP_K() -------------------------------------------------------- */ void ANT_ranking_function_puurula_idf::relevance_rank_top_k(ANT_search_engine_result *accumulator, ANT_search_engine_btree_leaf *term_details, ANT_impact_header *impact_header, ANT_compressable_integer *impact_ordering, long long trim_point, double prescalar, double postscalar, double query_frequency) { long long docid; double rsv, tf, query_length, query_occurences, prior; ANT_compressable_integer *current, *end; query_length = accumulator->get_term_count(); query_occurences = query_frequency; // this has already been transformed by the TFxIDF equation. impact_header->impact_value_ptr = impact_header->impact_value_start; impact_header->doc_count_ptr = impact_header->doc_count_start; current = impact_ordering; while (impact_header->doc_count_ptr < impact_header->doc_count_trim_ptr) { docid = -1; end = current + *impact_header->doc_count_ptr; while (current < end) { docid += *current++; tf = *impact_header->impact_value_ptr; tf = log(1.0 + tf / unique_terms_in_document[docid]) * log((double)documents / (double)term_details->global_document_frequency); // L0 norm version tf = max(tf - g * pow(tf, g), 0); if (tf != 0) { /* There must be some TF component to the score or else the rsv == 0 which is equivelant to the term not occuring */ rsv = query_occurences * log((tf * unique_terms_in_collection) / u + 1.0); if (accumulator->is_zero_rsv(docid)) // unseen before now so add the document prior { prior = log(1.0 - discounted_document_lengths[(size_t)docid] / (tfidf_discounted_document_lengths[(size_t)docid] + u)); accumulator->add_rsv(docid, quantize(query_length * prior + rsv, maximum_collection_rsv, minimum_collection_rsv)); } else // seen so we have already added the prior accumulator->add_rsv(docid, quantize(rsv, maximum_collection_rsv, minimum_collection_rsv)); } } current = end; impact_header->impact_value_ptr++; impact_header->doc_count_ptr++; } #pragma ANT_PRAGMA_UNUSED_PARAMETER }
/* Identify preamble sequence */ bool detectPreamble(void) { int transitions = 0; int c; // preamble sequence is based on the 9th symbol (either 0x55 or 0xAA) if (quantize(9)) { for (c = 0; c < 8; c++) { transitions += quantize(c) > quantize(c + 1); } } else { for (c = 0; c < 8; c++) { transitions += quantize(c) < quantize(c + 1); } } return transitions == 4 && abs(_threshold) < 15500; }
/* Extract byte from ring buffer starting location l */ inline uint8_t extractByte(int l) { uint8_t byte = 0; int c; for (c = 0; c < 8; c++) { byte |= quantize(l + c) << (7 - c); } return byte; }
void MotionRecognizer::addLearningData(vector<kmVecPair> &data, Motion motion) { vector<unsigned long> *seq = new vector<unsigned long>(); vector<kmVec3> norm; normalize(data, norm); quantize(norm, *seq); // Save it to buffer m_sequences[motion].push_back(seq); }
MeshBuilder::MeshNode* MeshBuilder::add_vertex(const Math::Vector3<float>& pt) { MeshNode* node = get_vertex(pt); if (node == nullptr) { float q = quantize(pt); node = new MeshNode(pt); _vertex_map[q].push_back(node); } return node; }
void processAudio(AudioBuffer &buffer) { FloatArray left = buffer.getSamples(LEFT_CHANNEL); FloatArray right = buffer.getSamples(RIGHT_CHANNEL); for(int i = 0; i<buffer.getSize(); i++){ if(abs(last-target) < 0.001){ last = target; target = noise->getNextSample()*range; } left[i] = last; last += getIncrement(); right[i] = hz.voltsToSample(quantize(hz.sampleToVolts(right[i]))); } }
void btOptimizedBvh::refitPartial(btStridingMeshInterface* meshInterface,const btVector3& aabbMin,const btVector3& aabbMax) { //incrementally initialize quantization values btAssert(m_useQuantization); btAssert(aabbMin.getX() > m_bvhAabbMin.getX()); btAssert(aabbMin.getY() > m_bvhAabbMin.getY()); btAssert(aabbMin.getZ() > m_bvhAabbMin.getZ()); btAssert(aabbMax.getX() < m_bvhAabbMax.getX()); btAssert(aabbMax.getY() < m_bvhAabbMax.getY()); btAssert(aabbMax.getZ() < m_bvhAabbMax.getZ()); ///we should update all quantization values, using updateBvhNodes(meshInterface); ///but we only update chunks that overlap the given aabb unsigned short quantizedQueryAabbMin[3]; unsigned short quantizedQueryAabbMax[3]; quantize(&quantizedQueryAabbMin[0],aabbMin,0); quantize(&quantizedQueryAabbMax[0],aabbMax,1); int i; for (i=0;i<this->m_SubtreeHeaders.size();i++) { btBvhSubtreeInfo& subtree = m_SubtreeHeaders[i]; //PCK: unsigned instead of bool unsigned overlap = testQuantizedAabbAgainstQuantizedAabb(quantizedQueryAabbMin,quantizedQueryAabbMax,subtree.m_quantizedAabbMin,subtree.m_quantizedAabbMax); if (overlap != 0) { updateBvhNodes(meshInterface,subtree.m_rootNodeIndex,subtree.m_rootNodeIndex+subtree.m_subtreeSize,i); subtree.setAabbFromQuantizeNode(m_quantizedContiguousNodes[subtree.m_rootNodeIndex]); } } }
void add_chords() { /* Davy added this function. The chordpip value of a chord is its quantized time; Set the chord value of the corresponding pip_array member to 1. This is the value that will get added to the base value if there is a chord change there */ int chord_pip, i; for (i=0; i<N_pips; i++) pip_array[i].chord = 0; /* probably already 0 */ for (i=0; i<N_chords; i++) { chord_pip=quantize(prechord[i].time); pip_array[chord_pip].chord=1; /* printf("chord at pip number %d\n", chord_pip); */ } }
static int* block_coeffs(IplImage *img, int* plane_coeffs) { CvSize size = cvGetSize(img); IplImage *b = cvCreateImage(size, IPL_DEPTH_8U, 1); IplImage *g = cvCreateImage(size, IPL_DEPTH_8U, 1); IplImage *r = cvCreateImage(size, IPL_DEPTH_8U, 1); IplImage *trans = cvCreateImage(size, IPL_DEPTH_16S, 1); int dim = plane_coeffs[0] + plane_coeffs[1] + plane_coeffs[2]; int sz = size.width*size.height/64*dim; int *buf = malloc(sizeof(int)*sz); unsigned *order_p0 = build_path(plane_coeffs[0], KERNS); unsigned *order_p1 = build_path(plane_coeffs[1], KERNS); unsigned *order_p2 = build_path(plane_coeffs[2], KERNS); cvSplit(img, b, g, r, NULL); wht2d(b, trans); quantize(trans, plane_coeffs[0], KERNS, order_p0, buf, dim); wht2d(g, trans); quantize(trans, plane_coeffs[1], KERNS, order_p1, buf+plane_coeffs[0], dim); wht2d(r, trans); quantize(trans, plane_coeffs[2], KERNS, order_p2, buf+plane_coeffs[0]+plane_coeffs[1], dim); cvReleaseImage(&trans); cvReleaseImage(&b); cvReleaseImage(&g); cvReleaseImage(&r); free(order_p0); free(order_p1); free(order_p2); return buf; }
static Errcode init_quantize(Aa_ink_data *aid, Ink_groups *igs) { int i; for (i=0; i<256; ++i) { dif_table[i] = quantize(i); } for (i=0; i<256; ++i) clip_table[i] = 0; for (i=2*256; i<3*256; ++i) clip_table[i] = 255; for (i=0; i<256; ++i) clip[i] = i; return Success; }
void compute_hash_codes(unsigned int *codes, float *X, int N, int nbins, float *min, float *max){ float range[DIM]; float qstep; int i; for(i=0; i<DIM; i++){ range[i] = fabs(max[i] - min[i]); // The range of the data range[i] += 0.01*range[i]; // Add somthing small to avoid having points exactly at the boundaries } qstep = max_range(range) / nbins; // The quantization step quantize(codes, X, min, qstep, N); // Function that does the quantization }
void gradientAngle(float** gradX, float** gradY, float** angle, float** angleApprox, int length, int width) { float a, b; int i,j; for(i = 0; i < length; i++) { for(j = 0; j < width; j++) { b = angle[i][j] = atan2(-gradY[i][j], gradX[i][j]) * 180 / PI; if(angle[i][j] < 0) angle[i][j] = 180.0 + angle[i][j]; // Quantisation de l'angle selon 4 directions [0,45,90,135] angleApprox[i][j] = quantize(angle[i][j]); } } }
Motion MotionRecognizer::recognize(vector<kmVecPair> &data) { vector<unsigned long> seq; vector<kmVec3> norm; double prob; double maxProb = 0; int maxMotion = 0; normalize(data, norm); // If all datas were discarded or there were no datas. if (norm.size() == 0) return UnknownMotion; quantize(norm, seq); // For every HMMs, calculate probabilities. for (int i = 0; i < MOTION_COUNT; i++) { for (int j = 0; j < seq.size(); j++) m_hmm[i]->addObservation(seq[j]); prob = exp(m_hmm[i]->viterbi() - m_hmm[i]->obsProb()); if (isnan(prob)) prob = 0; /*char str[100]; sprintf(str, "%f", prob); CCLog(str);*/ // If there is a motion that has max probability, // that motion would be the motion recognized. if (prob > maxProb) { maxProb = prob; maxMotion = i; } m_hmm[i]->reset(); } // If max probability is less than threshold, // we cannot be sure that this is actual motion recognized. if (maxProb < PROBABILITY_THRESHOLD) return UnknownMotion; return (Motion)maxMotion; }