当前位置: 首页>>代码示例>>C++>>正文


C++ image::resize方法代码示例

本文整理汇总了C++中image::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ image::resize方法的具体用法?C++ image::resize怎么用?C++ image::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在image的用法示例。


在下文中一共展示了image::resize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: RGBtoHSI

/*-----------------------------------------------------------------------**/
void colorSpace::RGBtoHSI(image &src, image &tgt){
	//cout<<"RGB->HSI\n";
	tgt.resize(src.getNumberOfRows(),src.getNumberOfColumns());
	float pi = 3.14159265358979f;
	for (int i=0; i<src.getNumberOfRows(); i++){	//for each pixel
		for (int j=0; j<src.getNumberOfColumns(); j++){
			//normalize RGB values
			float sum = (float)(src.getPixel(i,j,RED) + src.getPixel(i,j,GREEN) + src.getPixel(i,j,BLUE));
			if(sum!=0){	//make sure not to div0
				float r = (float)src.getPixel(i,j,RED)/sum;
				float g = (float)src.getPixel(i,j,GREEN)/sum;
				float b = (float)src.getPixel(i,j,BLUE)/sum;
				float h;
				if(b<=g){	//0<h<2pi
					h = acos( ( .5f*((r-g)+(r-b)) ) / pow((r-g)*(r-g)+(r-b)*(g-b),.5f) );
				}else{	//b > g
					h = 2.0f*pi - acos( .5f*((r-g)+(r-b)) / pow((r-g)*(r-g)+(r-b)*(g-b),.5f) );
				}
				float s = 1.0f-3.0f*min(min(r,g),b);	//0<s<1
				float in = sum/(3.0f*255.0f);		//0<in<1
				//convert h,s,i to appropriate ranges for storage in image
				int hue = round(h*255.0f/(2.0f*pi));	//255/2 instead of 180 (Intead of 360)
				int sat = round(s*255.0f);	//255 instead of 100
				int inten = round(in*255.0f);
				tgt.setPixel(i,j,H,hue);
				tgt.setPixel(i,j,S,sat);
				tgt.setPixel(i,j,I,inten);
			}else{
				tgt.setPixel(i,j,H,0);
				tgt.setPixel(i,j,S,0);
				tgt.setPixel(i,j,I,0);
			}
		}
	}
}
开发者ID:7yl4r,项目名称:Image-Processing-Toolbox,代码行数:36,代码来源:colorSpace.cpp

示例2: apply

  // merge float channels
  bool mergeOCPToImage::apply(const matrix<float>& c1,
                              const matrix<float>& c2,
                              const matrix<float>& c3,
                              image& img) const {

    point p;              // coordinates
    float r,g,b;          // unnormed RGB channels
    float RG, BY, WB;     // opponent colour channels

    if ((c1.size() != c2.size()) || (c1.size() != c3.size())) {
      setStatusString("sizes of channels do not match");
      return false;
    }

    img.resize(c1.size(),rgbPixel(),false,false);

    for (p.y=0;p.y<img.rows();p.y++) {
      for (p.x=0;p.x<img.columns();p.x++) {

	RG = c1.at(p);
	BY = c2.at(p);
	WB = c3.at(p);

        b = BY*0.666666666667f;
        //
	r = WB + RG - b;
	g = WB - RG - b;
	b = WB + BY*1.3333333333333f;

	// truncate r,g and b if the value is not in intervall [0..1]
	// can happen due to rounding errors in split operation
	if (r<0.0f) {
          r=0.0f;
        } else if (r>1.0f) {
          r=1.0f;
        }

	if (g<0.0f) {
          g=0.0f;
        } else if (g>1.0f) {
          g=1.0f;
        }

	if (b<0.0f) {
          b=0.0f;
        } else if (b>1.0f) {
          b=1.0f;
        }

	img.at(p).set(static_cast<ubyte>(255.0f*r),
                      static_cast<ubyte>(255.0f*g),
                      static_cast<ubyte>(255.0f*b),
                      0);
      }
    }

    return true;
  };
开发者ID:mvancompernolle,项目名称:ai_project,代码行数:59,代码来源:ltiMergeOCPToImage.cpp

示例3: addGrey

/*-----------------------------------------------------------------------**/
void add::addGrey(image &src, image &tgt, ROI roi, int value){
	tgt.resize(src.getNumberOfRows(), src.getNumberOfColumns());
	for (int i=0; i<src.getNumberOfRows(); i++){
		for (int j=0; j<src.getNumberOfColumns(); j++){
			if (roi.InROI(i,j)){
				tgt.setPixel(i,j,src.getPixel(i,j) + value); 
				//check for values outside range
		             	if (tgt.getPixel(i,j) > 255)
					tgt.setPixel(i,j,255);
				else if (tgt.getPixel(i,j) < 0)
					tgt.setPixel(i,j,0);	
			}else{	
				tgt.setPixel(i,j,src.getPixel(i,j));
			}
		}
	}
}
开发者ID:7yl4r,项目名称:Image-Processing-Toolbox,代码行数:18,代码来源:add.cpp

示例4: performQuantization

  // Quantization takes place here!
  bool medianCut::performQuantization(const image& src,
                                      image& dest,
                                      channel8& mask,
                                      palette &thePalette) const {

    // parameters and const variables
    const parameters& param = getParameters();
    const int imageRows=src.rows();          // number of rows in src
    const int imageCols=src.columns();       // number of columns in src

    // resize destination containers
    dest.resize(imageRows,imageCols,rgbPixel(),false,false);
    mask.resize(imageRows,imageCols,ubyte(),false,false);

    // Variables
    int row,col;            // row, column counters
    int r,g,b;              // red,green,blue
    ivector iVec(3);        // int-vector

    std::list<boxInfo> theLeaves; // list of leaves (tree without root
                                  // and nodes)
    std::list<boxInfo>::iterator  splitPos;   // position to split
    std::list<boxInfo>::iterator  iter;       // iterator for theLeaves

    // create histogram with desired pre-quantization dimensions from src
    histogram theHist(3,param.preQuant);

    const float factor = param.preQuant/256.0f;

    for (row = 0 ; row < imageRows ; row++) {
      for (col = 0 ; col < imageCols ; col++) {

        r = static_cast<int>(src.at( row,col ).getRed()   * factor);
        g = static_cast<int>(src.at( row,col ).getGreen() * factor);
        b = static_cast<int>(src.at( row,col ).getBlue()  * factor);
        
        // insert point with quantized color
        dest.at(row,col).set((r*256+128)/param.preQuant,
                             (g*256+128)/param.preQuant,
                             (b*256+128)/param.preQuant,0); 

        iVec[0] = r;
        iVec[1] = g;
        iVec[2] = b;

        theHist.put(iVec);
      }
    }

    // initialization of first box of list (the whole histogram)
    boxInfo theBox(rgbPixel(0,0,0),
                   rgbPixel(param.preQuant-1,
                            param.preQuant-1,
                            param.preQuant-1));

    computeBoxInfo(theHist,theBox);

    // return, if desired number of colors smaller than colors in
    // pre-quantized image
    if (theBox.colors < param.numberOfColors) {

      thePalette.resize(theBox.colors,rgbPixel(),false,false);

      // prepare palette     
      int i = 0;
      for (r=0;r<param.preQuant;++r) {
        for (g=0;g<param.preQuant;++g) {
          for (b=0;b<param.preQuant;++b) {
            iVec[0] = r;
            iVec[1] = g;
            iVec[2] = b;
            if (theHist.at(iVec) > 0) {
              thePalette.at(i).set((r*256+128)/param.preQuant,
                                   (g*256+128)/param.preQuant,
                                   (b*256+128)/param.preQuant);
            }
          }
        }
      }

      // use the palette to generate the corresponding channel
      usePalette colorizer;
      colorizer.apply(dest,thePalette,mask);
      
      return true;
    }

    // Push first box into List
    theLeaves.push_back(theBox);

    // MAIN LOOP (do this until you have enough leaves (count), or no
    // splittable boxes (entries))
    int count, entries=1;  // auxiliary variables for the main loop
    for (count=1; (count<param.numberOfColors) && (entries!=0); count++) {

      // find box with largest number of entries from list
      entries = 0;
      for (iter = theLeaves.begin() ; iter != theLeaves.end() ; iter++) {
        if ( (*iter).colorFrequency > entries ) {
//.........这里部分代码省略.........
开发者ID:mvancompernolle,项目名称:ai_project,代码行数:101,代码来源:ltiMedianCut.cpp

示例5: HSItoRGB

void colorSpace::HSItoRGB(image &src, image &tgt){
	//cout<<"HSI->RGB\n";
	tgt.resize(src.getNumberOfRows(),src.getNumberOfColumns());
	float pi = 3.14159265358979f;
	for (int i=0; i<src.getNumberOfRows(); i++){	//for each pixel
		for (int j=0; j<src.getNumberOfColumns(); j++){
			//re-normalize h,s,i
			float h = ((float)src.getPixel(i,j,H))*pi*2.0f/255.0f;//255/2 instead of 180
			float s = ((float)src.getPixel(i,j,S))/255.0f;//255 instead of 100
			float in= ((float)src.getPixel(i,j,I))/255.0f;
			/*
			//compute x y z
			float x = in*(1.0f-s);
			float y = in*( 1.0f + (s*cos(h) / cos(pi/3.0f-h)) );
			float z = 3.0f*in-(x+y);
			float r,g,b;	//set rgb
			if(h<(2.0f*pi/3.0f)){
				b = x;
				r = y;
				g = z;
			}else if(h<(4.0f*pi/3.0f)){//&&2pi/3<=h
				r = x; 
				g = y;
				b = z;
			}else{	//less than 2pi && 4pi/3<=h
				g = x;
				b = y;
				r = z;
			}*/
			float x = in*(1.0f-s);
			float y,z,r,g,b;
			if(h<(2.0f*pi/3.0f)){
				y = in*( 1.0f + (s*cos(h) / cos(pi/3.0f-h)) );
				z = 3.0f*in-(x+y);
				b = x;
				r = y;
				g = z;
			}else if(h<(4.0f*pi/3.0f)){//&&2pi/3<=h
				h -= 2*pi/3;
				y = in*( 1.0f + (s*cos(h) / cos(pi/3.0f-h)) );
				z = 3.0f*in-(x+y);
				r = x; 
				g = y;
				b = z;
			}else{  //less than 2pi && 4pi/3<=h
				h -= 4*pi/3;
				y = in*( 1.0f + (s*cos(h) / cos(pi/3.0f-h)) );
				z = 3.0f*in-(x+y);
				g = x;
				b = y;
				r = z;
			}
			//convert normalized rgb to 0-255 range
			int rr = (int)round(r*255.0f);
			int gg = (int)round(g*255.0f);
			int bb = (int)round(b*255.0f);
			tgt.setPixel(i,j,RED,rr);
			tgt.setPixel(i,j,GREEN,gg);
			tgt.setPixel(i,j,BLUE,bb);
		}
	}
}	
开发者ID:7yl4r,项目名称:Image-Processing-Toolbox,代码行数:62,代码来源:colorSpace.cpp


注:本文中的image::resize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。