本文整理汇总了C++中image::columns方法的典型用法代码示例。如果您正苦于以下问题:C++ image::columns方法的具体用法?C++ image::columns怎么用?C++ image::columns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类image
的用法示例。
在下文中一共展示了image::columns方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
};
示例2: apply
// split image into 8-bit channels
// N.B.: when casting the transformation result to unsigned shorts
// (8-bit channel), major rounding errors will occur.
// As a result, the merging operation might
// produce negative values or values > 1, which are truncated subsequently.
// When accurate X, Y and Z channels are required, prefer float channels!
bool splitImageToxyY::apply(const image& img,
channel8& c1,
channel8& c2,
channel8& c3) const {
point p; // coordinates
rgbPixel pix; // single Pixel Element in RGB-values...
float Y; // channels
float X, XYZ; // help variables
// make the channels size of source image...
c1.resize(img.rows(),img.columns(),0,false,false);
c2.resize(img.rows(),img.columns(),0,false,false);
c3.resize(img.rows(),img.columns(),0,false,false);
for (p.y=0;p.y<img.rows();p.y++)
for (p.x=0;p.x<img.columns();p.x++) {
// take pixel at position p
pix = img.at(p);
// see Gonzales & Woods for explanation of magic numbers
X = (((float)(pix.getRed())) *0.412453f +
((float)(pix.getGreen())) *0.357580f +
((float)(pix.getBlue())) *0.180423f)/255.0f; // x
Y = (((float)(pix.getRed())) *0.212671f +
((float)(pix.getGreen())) *0.715160f +
((float)(pix.getBlue())) *0.072169f)/255.0f; // y
XYZ = (((float)(pix.getRed())) *0.644458f +
((float)(pix.getGreen())) *1.191933f +
((float)(pix.getBlue())) *1.202819f)/255.0f; // Y
if (XYZ>0.0f) {
c1.at(p) = (ubyte)(X/XYZ*255.0f); // x
c2.at(p) = (ubyte)(Y/XYZ*255.0f); // y
}
else {
c1.at(p) = 0; // x
c2.at(p) = 0; // y
}
c3.at(p) = (ubyte)(Y*255.0f); // Y
} // loop
return true;
}
示例3: getAverage
bool brightRGB::getAverage(const image& img,dvector& dest) const{
const rgbPixel transColor = getParameters().transColor;
dvector avg(3,0.0);
image::const_iterator it = img.begin();
// check for empty image
if (img.columns()==0 || img.rows()==0) {
setStatusString("image empty");
dest.resize(0);
return false;
}
if(getParameters().transparent) {
int counter = 0;
while(it != img.end()) {
if(*it != transColor) {
avg.at(0) += (*it).getRed();
avg.at(1) += (*it).getGreen();
avg.at(2) += (*it).getBlue();
++counter;
}
it++;
}
// check for completely transparent image
if (counter==0) {
setStatusString("only transparent pixels");
dest.resize(0);
return false;
}
avg.divide(counter);
} else { // no transparent color
while(it != img.end()) {
avg.at(0) += (*it).getRed();
avg.at(1) += (*it).getGreen();
avg.at(2) += (*it).getBlue();
it++;
}
avg.divide(img.columns()*img.rows());
}
// values between 0 and 1
dest.divide(avg, 255.);
return true;
};
示例4: show
/*
* shows an lti::mathObject
* @param data the object to be shown.
*/
bool fastViewer::show(const image& img) {
// Draw screen onto display
if (img.rows()>0 && img.columns()>0) {
if (data.size() == img.size()) {
data.fill(img);
} else {
destroyImage();
createImage(img);
}
} else {
setStatusString("empty image");
return false;
}
if (useShareMemory) {
XShmPutImage(display_info.display,
display_info.win,
display_info.gc,
display_info.shmimage,
0, 0, 0, 0,
display_info.width,
display_info.height, false);
} else {
XPutImage(display_info.display,
display_info.win,
display_info.gc,
display_info.shmimage,
0, 0, 0, 0,
display_info.width,
display_info.height);
}
XSync(display_info.display,0);
return true;
}
示例5: createImage
/*
* create XImage
*/
void fastViewer::createImage(const image& img) {
int screen;
display_info_s& di = display_info;
XWindowAttributes win_attributes;
bool resizeWin = false;
if ((di.height != img.rows()) ||
(di.width != img.columns())) {
resizeWin = true;
}
di.height = img.rows();
di.width = img.columns();
if (di.win == 0) {
createWindow();
}
if (resizeWin) {
XResizeWindow(di.display,di.win,di.width,di.height);
}
screen = DefaultScreen(di.display);
XGetWindowAttributes(di.display, di.win, &win_attributes);
di.depth = win_attributes.depth;
// TODO: maybe screen->root_depth is more precise than win_attr.depth
// We should try it.
// check if the X-Server has a 32 bit interface
if (di.depth < 24) {
throw exception("Error: Fast Viewer works only with 32 bit depth!");
}
if (useShareMemory) {
//
// Shared Memory Setup
//
di.shmimage = XShmCreateImage(di.display,
DefaultVisual(di.display, screen),
di.depth, ZPixmap, NULL, &shminfo,
di.width,
di.height);
if(isNull(di.shmimage)) {
throw exception("fastViewer::shmimage == NULL:");
}
int sharedMemSize = di.shmimage->bytes_per_line * di.shmimage->height;
shminfo.shmid = shmget(IPC_PRIVATE,
sharedMemSize,
IPC_CREAT | 0777);
if(shminfo.shmid < 0) {
std::string str;
str = "fastViewer::shmget failed:";
str += strerror(errno);
throw exception(str);
}
shminfo.shmaddr = (char *) shmat(shminfo.shmid, (void *) 0, 0);
if (shminfo.shmaddr == 0) {
std::string str;
str = "fastViewer::shmmat failed:";
str += std::strerror(errno);
throw exception(str);
}
di.shmimage->data = shminfo.shmaddr;
XShmAttach(di.display, &shminfo);
data.useExternData(di.height,di.width,(rgbPixel*)di.shmimage->data);
data.fill(img);
} else {
//
// without shared memory
//
const int blockSize = img.rows()*img.columns()*4;
remoteData = new char[blockSize];
data.useExternData(di.height,di.width,(rgbPixel*)remoteData);
data.fill(img);
di.shmimage = XCreateImage(di.display,
DefaultVisual(di.display, screen),
di.depth, ZPixmap, 0,
remoteData,
di.width,
di.height,8,0);
if(isNull(di.shmimage)) {
throw exception("fastViewer::shmimage == NULL:");
}
}
//.........这里部分代码省略.........
示例6: getMedian
bool brightRGB::getMedian(const image& img,dvector& dest) const{
// image empty?
if (img.empty()) {
setStatusString("image empty");
dest.resize(0);
return false;
}
const rgbPixel transColor = getParameters().transColor;
dest.resize(3);
ivector hist0(256,0);
ivector hist1(256,0);
ivector hist2(256,0);
image::const_iterator it = img.begin();
if(getParameters().transparent) {
while(it != img.end()) {
if(*it != transColor) {
++hist0.at((*it).getRed());
++hist1.at((*it).getGreen());
++hist2.at((*it).getBlue());
}
it++;
}
const int counterHalf = hist0.sumOfElements()/2;
// check for complete image transparent
if (counterHalf==0) {
setStatusString("only transparent pixels");
dest.resize(0);
return false;
}
int i,s;
i=-1,s=0;
while(++i<256 && s<counterHalf) {
s += hist0.at(i);
}
dest.at(0) = i-1;
i=-1,s=0;
while(++i<256 && s<counterHalf) {
s += hist1.at(i);
}
dest.at(1) = i-1;
i=-1,s=0;
while(++i<256 && s<counterHalf) {
s += hist2.at(i);
}
dest.at(2) = i-1;
} else { // no transparent color
while(it != img.end()) {
++hist0.at((*it).getRed());
++hist1.at((*it).getGreen());
++hist2.at((*it).getBlue());
it++;
}
const int counterHalf = img.columns()*img.rows()/2;
int i,s;
i=-1,s=0;
while(++i<256 && s<counterHalf) {
s += hist0.at(i);
}
dest.at(0) = i-1;
i=-1,s=0;
while(++i<256 && s<counterHalf) {
s += hist1.at(i);
}
dest.at(1) = i-1;
i=-1,s=0;
while(++i<256 && s<counterHalf) {
s += hist2.at(i);
}
dest.at(2) = i-1;
}
// normalize to 0..1
dest.divide(255);
return true;
};
示例7: 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 ) {
//.........这里部分代码省略.........