Пример #1
0
void StringModel::EndOfData() {
    // Calculate the probability vector of characters
    Quantization(&char_prob_, char_count_, 16);
    char_count_.clear();
    // Calculate the probability vector of string lengths
    Quantization(&length_prob_, length_count_, 8);
    length_count_.clear();
}
Пример #2
0
void __fastcall TForm1::Button4Click(TObject *Sender)
{
        int flag=StrToInt(Edit1->Text);
        TrackBar1Update();
        Image1->Picture->Bitmap=map;
        Image2->Visible=true;
        Image2->Picture->Bitmap=map;
        for(int x=0;x<map->Width;x++)
        for(int y=0;y<map->Height;y++){
                double *buff=new double[3];
                double *N=new double[3];
                buff[0]=GetRValue(map->Canvas->Pixels[x][y]);
                buff[1]=GetGValue(map->Canvas->Pixels[x][y]);
                buff[2]=GetBValue(map->Canvas->Pixels[x][y]);

                if(ComboBox1->Text=="RGB"){
                                N[0]=N[1]=N[2]=256/flag;
                                buff=Quantization(buff,N);
                }
                else if(ComboBox1->Text=="YUV"){
                                buff=RtoY(buff,0);
                                buff[1]+=(222.36/2);
                                buff[2]+=(313.65/2);
                                N[0]=256/flag;
                                N[1]=222.36/flag;
                                N[2]=313.65/flag;
                                buff[1]-=(222.36/2);
                                buff[2]-=(313.65/2);
                                buff=Quantization(buff,N);
                                buff=YtoR(buff,0);
                }
                else if(ComboBox1->Text=="YIQ"){
                                buff=RtoY(buff,1);
                                buff[1]+=(303.96/2);
                                buff[2]+=(266.22/2);
                                N[0]=256/flag;
                                N[1]=303.96/flag;
                                N[2]=266.22/flag;
                                buff[1]-=(303.96/2);
                                buff[2]-=(266.22/2);
                                buff=Quantization(buff,N);
                                buff=YtoR(buff,1);
                }
                for(int i=0;i<3;i++){
                        if(buff[i]>255)        buff[i]=255;
                        else if(buff[i]<0)     buff[i]=0;
                }
                Image2->Canvas->Pixels[x][y]=(TColor)RGB((int)buff[0],(int)buff[1],(int)buff[2]);

                delete buff;
        }
}
Пример #3
0
int main() 
{   ......
    // register range of protected data using reference LUT
    asm("set_data @imageEx, 262144, @lut_imageEx, 64");
    DiscreteCosine(imageData, imageEx);
    Quantization(imageEx, imageExtended);
    ......
}
Пример #4
0
void TableCategorical::EndOfData() {
    // Determine cell size
    cell_size_ = (target_range_ > 100 ? 16 : 8);
    for (size_t i = 0; i < dynamic_list_.size(); ++i ) {
        CategoricalStats& stats = dynamic_list_[i];
        // Extract count vector
        std::vector<int> count;
        count.swap(stats.count);

        // We might need to resize count vector
        count.resize(target_range_);
        std::vector<Prob> prob;

        // Mark empty entries, since we are allowed to make mistakes,
        // we can mark entries that rarely appears as empty
        int total_count = 0, current_tol = 0;
        for (size_t j = 0; j < count.size(); ++j )
            total_count += count[j];
        for (size_t j = 0; j < count.size(); ++j )
        if (count[j] + current_tol <= total_count * err_) {
            current_tol += count[j];
            count[j] = 0;
        }
        // We add back the mistake count to the most likely category
        size_t most_likely_category = 0;
        for (size_t j = 0; j < count.size(); ++j )
        if (count[j] > count[most_likely_category])
            most_likely_category = j;
        count[most_likely_category] += current_tol;

        // Quantization
        Quantization(&prob, count, cell_size_);     

        // Update model cost
        for (size_t j = 0; j < count.size(); j++ )
        if (count[j] > 0) {
            Prob p = (j == count.size() - 1 ? GetOneProb() : prob[j])
                        - (j == 0 ? GetZeroProb() : prob[j - 1]);
            model_cost_ += count[j] * (- log2(CastDouble(p)) ); 
        }
        // Write back to dynamic list
        stats.prob = prob;
    }
    // Add model description length to model cost
    model_cost_ += GetModelDescriptionLength();
}
Пример #5
0
void __fastcall TForm1::Button3Click(TObject *Sender)
{
        int flag=StrToInt(Edit1->Text);
        if(Image2->Visible==false){
                Image2->Visible=true;
                Image2->Picture->Bitmap=graylevel;
        }
        TrackBar1Update();
        Image1->Picture->Bitmap=graylevel;
        for(int x=0;x<graylevel->Width;x++)
        for(int y=0;y<graylevel->Height;y++){
                double *buff=new double[3];
                double *N=new double[3];
                N[0]=N[1]=N[2]=256/flag;
                buff[0]=GetGValue(graylevel->Canvas->Pixels[x][y]);
                buff[1]=buff[2]=buff[0];
                buff=Quantization(buff,N);
                Image1->Canvas->Pixels[x][y]=(TColor)RGB(buff[0],buff[1],buff[2]);
        }
}
Пример #6
0
OperationsModel::OperationsModel()
            : root(std::unique_ptr<Node>(new Node()))
            , controller(std::unique_ptr<Controller>(new Controller()))
      {
      beginResetModel();
                  // - initialize opeations with their default values
                  // - string lists below should match Operation enum values
      Node *quantValue = new Node;
      quantValue->name = "Quantization";
      quantValue->oper.type = MidiOperation::Type::QUANT_VALUE;
      quantValue->oper.value = (int)TrackOperations().quantize.value;
      quantValue->values.push_back("Value from preferences");
      quantValue->values.push_back("Quarter");
      quantValue->values.push_back("Eighth");
      quantValue->values.push_back("16th");
      quantValue->values.push_back("32nd");
      quantValue->values.push_back("64th");
      quantValue->values.push_back("128th");
      quantValue->parent = root.get();
      root->children.push_back(std::unique_ptr<Node>(quantValue));
      controller->quantValue = quantValue;


      Node *reduceToShorter = new Node;
      reduceToShorter->name = "Reduce to shortest note in bar";
      reduceToShorter->oper.type = MidiOperation::Type::QUANT_REDUCE;
      reduceToShorter->oper.value = Quantization().reduceToShorterNotesInBar;
      reduceToShorter->parent = quantValue;
      quantValue->children.push_back(std::unique_ptr<Node>(reduceToShorter));


//      Node *humanPerformance = new Node;
//      humanPerformance->name = "Human performance";
//      humanPerformance->oper.type = MidiOperation::Type::QUANT_HUMAN;
//      humanPerformance->oper.value = Quantization().humanPerformance;
//      humanPerformance->parent = quantValue;
//      quantValue->children.push_back(std::unique_ptr<Node>(humanPerformance));
//      controller->quantHuman = humanPerformance;


      Node *useDots = new Node;
      useDots->name = "Use dots";
      useDots->oper.type = MidiOperation::Type::USE_DOTS;
      useDots->oper.value = TrackOperations().useDots;
      useDots->parent = root.get();
      root->children.push_back(std::unique_ptr<Node>(useDots));

      Node *useMultipleVoices = new Node;
      useMultipleVoices->name = "Multiple voices";
      useMultipleVoices->oper.type = MidiOperation::Type::USE_MULTIPLE_VOICES;
      useMultipleVoices->oper.value = TrackOperations().useMultipleVoices;
      useMultipleVoices->parent = root.get();
      root->children.push_back(std::unique_ptr<Node>(useMultipleVoices));
      controller->multipleVoices = useMultipleVoices;


      // ------------- tuplets --------------

      Node *searchTuplets = new Node;
      searchTuplets->name = "Search tuplets";
      searchTuplets->oper.type = MidiOperation::Type::TUPLET_SEARCH;
      searchTuplets->oper.value = TrackOperations().tuplets.doSearch;
      searchTuplets->parent = root.get();
      root->children.push_back(std::unique_ptr<Node>(searchTuplets));
      controller->searchTuplets = searchTuplets;


      Node *duplets = new Node;
      duplets->name = "Duplets (2)";
      duplets->oper.type = MidiOperation::Type::TUPLET_2;
      duplets->oper.value = TrackOperations().tuplets.duplets;
      duplets->parent = searchTuplets;
      searchTuplets->children.push_back(std::unique_ptr<Node>(duplets));
      controller->duplets = duplets;


      Node *triplets = new Node;
      triplets->name = "Triplets (3)";
      triplets->oper.type = MidiOperation::Type::TUPLET_3;
      triplets->oper.value = TrackOperations().tuplets.triplets;
      triplets->parent = searchTuplets;
      searchTuplets->children.push_back(std::unique_ptr<Node>(triplets));
      controller->triplets = triplets;


      Node *quadruplets = new Node;
      quadruplets->name = "Quadruplets (4)";
      quadruplets->oper.type = MidiOperation::Type::TUPLET_4;
      quadruplets->oper.value = TrackOperations().tuplets.quadruplets;
      quadruplets->parent = searchTuplets;
      searchTuplets->children.push_back(std::unique_ptr<Node>(quadruplets));
      controller->quadruplets = quadruplets;


      Node *quintuplets = new Node;
      quintuplets->name = "Quintuplets (5)";
      quintuplets->oper.type = MidiOperation::Type::TUPLET_5;
      quintuplets->oper.value = TrackOperations().tuplets.quintuplets;
      quintuplets->parent = searchTuplets;
      searchTuplets->children.push_back(std::unique_ptr<Node>(quintuplets));
      controller->quintuplets = quintuplets;


      Node *septuplets = new Node;
      septuplets->name = "Septuplets (7)";
      septuplets->oper.type = MidiOperation::Type::TUPLET_7;
      septuplets->oper.value = TrackOperations().tuplets.septuplets;
      septuplets->parent = searchTuplets;
      searchTuplets->children.push_back(std::unique_ptr<Node>(septuplets));
      controller->septuplets = septuplets;


      Node *nonuplets = new Node;
      nonuplets->name = "Nonuplets (9)";
      nonuplets->oper.type = MidiOperation::Type::TUPLET_9;
      nonuplets->oper.value = TrackOperations().tuplets.nonuplets;
      nonuplets->parent = searchTuplets;
      searchTuplets->children.push_back(std::unique_ptr<Node>(nonuplets));
      controller->nonuplets = nonuplets;

      // ------------------------------------

      Node *pickupMeasure = new Node;
      pickupMeasure->name = "Recognize pickup measure";
      pickupMeasure->oper.type = MidiOperation::Type::PICKUP_MEASURE;
      pickupMeasure->oper.value = TrackOperations().pickupMeasure;
      pickupMeasure->parent = root.get();
      root->children.push_back(std::unique_ptr<Node>(pickupMeasure));
      controller->pickupMeasure = pickupMeasure;


      Node *swing = new Node;
      swing->name = "Detect swing";
      swing->oper.type = MidiOperation::Type::SWING;
      swing->oper.value = (int)TrackOperations().swing;
      swing->values.push_back("None (1:1)");
      swing->values.push_back("Swing (2:1)");
      swing->values.push_back("Shuffle (3:1)");
      swing->parent = root.get();
      root->children.push_back(std::unique_ptr<Node>(swing));


      Node *changeClef = new Node;
      changeClef->name = "Clef may change along the score";
      changeClef->oper.type = MidiOperation::Type::CHANGE_CLEF;
      changeClef->oper.value = TrackOperations().changeClef;
      changeClef->parent = root.get();
      root->children.push_back(std::unique_ptr<Node>(changeClef));


      Node *splitDrums = new Node;
      splitDrums->name = "Split drum set";
      splitDrums->oper.type = MidiOperation::Type::SPLIT_DRUMS;
      splitDrums->oper.value = TrackOperations().drums.doSplit;;
      splitDrums->parent = root.get();
      root->children.push_back(std::unique_ptr<Node>(splitDrums));
      controller->splitDrums = splitDrums;


      Node *showStaffBracket = new Node;
      showStaffBracket->name = "Show staff bracket";
      showStaffBracket->oper.type = MidiOperation::Type::SHOW_STAFF_BRACKET;
      showStaffBracket->oper.value = TrackOperations().drums.showStaffBracket;
      showStaffBracket->parent = splitDrums;
      splitDrums->children.push_back(std::unique_ptr<Node>(showStaffBracket));
      controller->showStaffBracket = showStaffBracket;


      Node *doLHRH = new Node;
      doLHRH->name = "Left/right hand separation";
      doLHRH->oper.type = MidiOperation::Type::DO_LHRH_SEPARATION;
      doLHRH->oper.value = LHRHSeparation().doIt;
      doLHRH->parent = root.get();
      root->children.push_back(std::unique_ptr<Node>(doLHRH));
      controller->LHRHdoIt = doLHRH;


      Node *LHRHMethod = new Node;
      LHRHMethod->name = "Separation method";
      LHRHMethod->oper.type = MidiOperation::Type::LHRH_METHOD;
      LHRHMethod->oper.value = (int)LHRHSeparation().method;
      LHRHMethod->values.push_back("Hand width");
      LHRHMethod->values.push_back("Fixed pitch");
      LHRHMethod->parent = doLHRH;
      doLHRH->children.push_back(std::unique_ptr<Node>(LHRHMethod));
      controller->LHRHMethod = LHRHMethod;


      Node *LHRHPitchOctave = new Node;
      LHRHPitchOctave->name = "Split pitch octave";
      LHRHPitchOctave->oper.type = MidiOperation::Type::LHRH_SPLIT_OCTAVE;
      LHRHPitchOctave->oper.value = (int)LHRHSeparation().splitPitchOctave;
      LHRHPitchOctave->values.push_back("C-1");
      LHRHPitchOctave->values.push_back("C0");
      LHRHPitchOctave->values.push_back("C1");
      LHRHPitchOctave->values.push_back("C2");
      LHRHPitchOctave->values.push_back("C3");
      LHRHPitchOctave->values.push_back("C4");
      LHRHPitchOctave->values.push_back("C5");
      LHRHPitchOctave->values.push_back("C6");
      LHRHPitchOctave->values.push_back("C7");
      LHRHPitchOctave->values.push_back("C8");
      LHRHPitchOctave->values.push_back("C9");
      LHRHPitchOctave->parent = LHRHMethod;
      LHRHMethod->children.push_back(std::unique_ptr<Node>(LHRHPitchOctave));
      controller->LHRHPitchOctave = LHRHPitchOctave;


      Node *LHRHPitchNote = new Node;
      LHRHPitchNote->name = "Split pitch note";
      LHRHPitchNote->oper.type = MidiOperation::Type::LHRH_SPLIT_NOTE;
      LHRHPitchNote->oper.value = (int)LHRHSeparation().splitPitchNote;
      LHRHPitchNote->values.push_back("C");
      LHRHPitchNote->values.push_back("C#");
      LHRHPitchNote->values.push_back("D");
      LHRHPitchNote->values.push_back("D#");
      LHRHPitchNote->values.push_back("E");
      LHRHPitchNote->values.push_back("F");
      LHRHPitchNote->values.push_back("F#");
      LHRHPitchNote->values.push_back("G");
      LHRHPitchNote->values.push_back("G#");
      LHRHPitchNote->values.push_back("A");
      LHRHPitchNote->values.push_back("A#");
      LHRHPitchNote->values.push_back("B");
      LHRHPitchNote->parent = LHRHMethod;
      LHRHMethod->children.push_back(std::unique_ptr<Node>(LHRHPitchNote));
      controller->LHRHPitchNote = LHRHPitchNote;

      //--------------------------------------------------------------------
      connect(this,
              SIGNAL(dataChanged(QModelIndex,QModelIndex)),
              SLOT(onDataChanged(QModelIndex)));
      controller->updateNodeDependencies(nullptr, true);
      endResetModel();
      }
Пример #7
0
Файл: dam.c Проект: dego-96/AIP
float DAM(float *data, int length, int resolution)
{
    float max, min;
    unsigned int *quant = Quantization(data, length, resolution, &max, &min);
    unsigned int *hist = makeHistogram(quant, length, resolution);

    // Discriminant Analysis
    int t, i;
    float sep_max = 0.0f;
    float sep;
    unsigned int num[2];
    float avr[2];
    float var[2];
    int threshold = 1;
    for (t = 1; t < resolution - 1; t++) {
        // Init
        num[0] = 0;
        num[1] = 0;
        avr[0] = 0.0;
        avr[1] = 0.0;
        var[0] = 0.0;
        var[1] = 0.0;
        // Get Num and Average
        for (i = 0; i < resolution; i++) {
            if (i < t) {
                num[0] += hist[i];
                avr[0] += (float)(hist[i] * i);
            } else {
                num[1] += *(hist + i);
                avr[1] += (float)(*(hist + i) * i);
            }
        }
        if (num[0] != 0 && num[1] != 0) {
            avr[0] = avr[0] / num[0];
            avr[1] = avr[1] / num[1];
        } else {
            num[0] = 1;
            num[1] = 1;
            continue;
        }
        // Get Variance
        for (i = 0; i < resolution; i++) {
            if (i < t) {
                var[0] += ((float)i - avr[0]) * ((float)i - avr[0]) * (hist[i]) / num[0];
            } else {
                var[1] += ((float)i - avr[1]) * ((float)i - avr[1]) * (hist[i]) / num[1];
            }
        }
        // Calc Separation
        sep = (float)num[0] * num[1] * (avr[0] - avr[1]) * (avr[0] - avr[1])
                / ((num[0] + num[1]) * (num[0] * var[0] + num[1] * var[1]));
        if (sep > sep_max) {
            sep_max = sep;
            threshold = t;
        }
    }

    free(quant);
    free(hist);

    return (float)threshold / (float)resolution * (max - min) + min;
//    return 30.0f;
}