Summary of Error visualization

Source: Internet
Author: User

Description of Error Visualization summary problem

When doing watermark work, the error between the original model and the watermark model needs to be measured. In order to see the error size more intuitively, the error can be visualized. is an example of a visual error, where the model on the left is the original Model A, the second line on the right is the approximate model of the original model given by an algorithm, and the third line on the right is a colored model that shows the error between the Model A and B by color, and the color bar displays the relationship between the different colors and the error size.

In the work of watermarking, the error of the original model and the watermark model may be measured, and the error can be easily calculated as the Euclidean distance between the corresponding points on the two models. Before calculating the error, first make sure that two models are aligned (the simplest processing can put the midpoint of the two models together), the code is as follows:

//Move the center of the two models together    //read out the original center    Double*rcenter =New Double[6];Charcenter_name[ -]; Ifstream Centerfile;sprintf(Center_name,"D:\\code\\geometryprocessing-1\\txt\\offset\\center.txt"); Centerfile.open (center_name,ios_base::in);if(Centerfile) {//Read into memoryCENTERFILE.SEEKG (0, centerfile.end);intLength = Centerfile.tellg (); CENTERFILE.SEEKG (0, Centerfile.beg);Char*buffer =New Char[Length];        Centerfile.read (buffer, length); Centerfile.close ();//Parse into array        STD:: istringstream ISS(buffer) ;inti =0; while(I <6) {ISS >> rcenter[i++]; }Delete[] buffer;//print or use it.} centerfile.close ();Doublecurrentitycenter[3];//** Store the center of current entity ' s bounding box *//    Doublefirstmeshcenter[3]; Entity_mesha->get_bb_center (Firstmeshcenter); for(inti =0; i<2;        ++i) {pgmeshentity* meshentity = (pgmeshentity*) meshlist[i];        mesh* mesh = Meshentity->get_mesh ();        Mesh::constvertexiter Cvit = Mesh->vertices_begin ();        Mesh::constvertexiter cvit_end = Mesh->vertices_end (); Meshentity->get_bb_center (Currentitycenter);Doubleoffset[3] = {0,0,0}; offset[0] =currentitycenter[0]-rcenter[0]; offset[1]= currentitycenter[1]-rcenter[1]; offset[2]= currentitycenter[2]-rcenter[2]; rcenter+=3;//** Update the leftmost point for the next entity *//        //** Adjust the position of all points of the current entity *//         for(; Cvit! = Cvit_end; ++cvit)            {Openmesh::vec3d Tmppoint = Mesh->point (Cvit); tmppoint[0]-= offset[0]; tmppoint[1]-= offset[1]; tmppoint[2]-= offset[2]; Mesh->set_point (Cvit.handle (), tmppoint);//** Modify Core mesh D.s. embedded in pgmeshentity D.s., updating the corresponding render in pgmeshentity D.s. is NE eded *//}//** Update the center point of pgmeshentity instance bounding box *//Meshentity->cal_bounding_box ();        Meshentity->update_rendering ();    Mesh->update_face_normals (); }
Error calculation

As already mentioned above, the error can be simply calculated as the Euclidean distance between the corresponding points of two models. The visual error is actually coloring the Model B (or a) and using color to represent the error. In particular, declare a vector errorb, which is used to store the distance of each point of model B from the corresponding point of Model A, and then set a colormap, according to the distance, select the color in the ColorMap, as the color of the midpoint of B, and then draw it. The error calculation code is as follows:

voidSequencewatermark::error_map () {baseentity * Entity_mesha;    BaseEntity * ENTITY_MESHB; Entity_mesha = meshlist[0]; ENTITY_MESHB = meshlist[1];    Polygonmesh::mesh * _mesha = ((Polygonmesh::P gmeshentity *) Entity_mesha)->get_mesh (); Polygonmesh::mesh * _MESHB = ((Polygonmesh::P gmeshentity *) ENTITY_MESHB)->get_mesh ();//amount of visualization    Vector<Double> Errorb;//For storing three-dimensional coordinates for each point    vectorxd acoor(3) ;vectorxd bcoor(3) ;intIA =0; for(AutoVa_it = _mesha->vertices_begin (); Va_it! = _mesha->vertices_end (); ++va_it, ia++) {AutoT_p = _mesha->point (Va_it.handle ()); acoor[0] = t_p[0]; acoor[1] = t_p[1]; acoor[2] = t_p[2];intIB =0;Doubledis =0.0; for(AutoVb_it = _meshb->vertices_begin (); Vb_it! = _meshb->vertices_end (); ++vb_it, ib++) {AutoT_PB = _meshb->point (Vb_it.handle ());if(ia = = IB) {bcoor[0] = t_pb[0]; bcoor[1] = t_pb[1]; bcoor[2] = t_pb[2];                dis = (acoor-bcoor). Norm (); Errorb.push_back (DIS); Break; }                    }    }Vector<Double>::iterator Max_it; Max_it = Max_element (Errorb.begin (), Errorb.end ());DoubleMaxd = *max_it;Vector<Double>::iterator Min_it; Min_it = Min_element (Errorb.begin (), Errorb.end ());DoubleMind = *min_it; Mesh::color CL;intv =0; for(AutoVit = _meshb->vertices_begin (); Vit! = _meshb->vertices_end (); ++vit, v++) {Errorb[v] =100.0f* (Errorb[v]-mind)/(Maxd-mind);DoubleCLAMPV = errorb[v]<99.0f? ERRORB[V]:99.0f; CLAMPV = CLAMPV >0.0f? CLAMPV:0.0f;intColorpercent = (int) CLAMPV;unsigned Char* Colorptr = errorcolormap + colorpercent *3; cl.values_[0] = colorptr[0]; cl.values_[1] = colorptr[1]; cl.values_[2] = colorptr[2]; _meshb->set_color (Vit.handle (), CL);//Dynamic display} _meshb->update_face_normals (); Entity_meshb->update_rendering ();

Finally, to make it easier to see, offset the position of the second model a little bit

    //For display convenience, offset the second framepgmeshentity* meshentity = (pgmeshentity*) meshlist[1];    mesh* mesh = Meshentity->get_mesh ();    Mesh::constvertexiter Cvit = Mesh->vertices_begin ();    Mesh::constvertexiter cvit_end = Mesh->vertices_end ();    Meshentity->get_bb_center (Currentitycenter);    Double radius = Meshentity->get_bb_radius (); Double offset[3] = {0,0,0}; offset[0] =currentitycenter[0] + radius; offset[1]= currentitycenter[1]; offset[2]= currentitycenter[2];//** Update the leftmost point for the next entity *//    //** Adjust the position of all points of the current entity *//     for(; Cvit! = Cvit_end; ++cvit)        {Openmesh::vec3d Tmppoint = Mesh->point (Cvit); tmppoint[0] + = offset[0]; tmppoint[1] + = offset[1]; tmppoint[2] + = offset[2]; Mesh->set_point (Cvit.handle (), tmppoint);//** Modify Core mesh D.s. embedded in pgmeshentity D.s., updating the corresponding render in pgmeshentity D.s. is NE eded *//}//** Update the center point of pgmeshentity instance bounding box *//Meshentity->cal_bounding_box ();    Meshentity->update_rendering (); Mesh->update_face_normals ();}

We use a simple model to validate the above code
Two models for input, model A on the left and model B to the right

To execute the results

Draw a color bar with matlab

Now that we've got the error map, but we still don't know the relationship between color and error, in other words, only the above results, we don't know whether the error of dark blue is big or small, so we need to map the color we use to represent the error to a color bar.
1. First enter a matrix map in MATLAB that represents the RGB values to be drawn by the color bar
2. Divide each value of MAP by 255, i.e. AMAP = map/255
3. Pass AMAP into the ColorMap function, i.e. execute ColorMap (AMAP)
4. Draw the result, i.e. execute figure;colorbar;
The results are as follows:

Summary of Error visualization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.