本文整理汇总了C++中ImageRGB::at方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageRGB::at方法的具体用法?C++ ImageRGB::at怎么用?C++ ImageRGB::at使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageRGB
的用法示例。
在下文中一共展示了ImageRGB::at方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: filterImage
void YellowColorFilter::filterImage(ImageRGB & image) {
// Image size;
int width = image.width();
int height = image.height();
// For every pixel in the image
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
// Get the RGB values
Rgb<unsigned char &> pixelRGB = image.at(x, y);
// To save the Hue, Saturation and Value
float hue, saturation, value;
// Convert RGB to HSV.
RGB2HSV(pixelRGB.red, pixelRGB.green, pixelRGB.blue, hue, saturation, value);
// If the color is yellow.
if (hue >= 25 && hue <= 60 && saturation >= 0.60) {
// If the color is within our yellow range, make the output pixel white.
pixelRGB.red = 255;
pixelRGB.green = 255;
pixelRGB.blue = 255;
}
else {
// Else make the pixel black.
pixelRGB.red = 0;
pixelRGB.green = 0;
pixelRGB.blue = 0;
}
}
}
}
示例2: floor
std::unique_ptr<ImageRGB> imageTransform::convert(const ImageRGB& oldImage) {
std::unique_ptr<ImageRGB> returnImage = std::make_unique<ImageRGB>(460, 110);
matrix m;
float *inverse = m.getInverseMatrix(theMatrix);
float a0 = inverse[0];
float a1 = inverse[1];
float a2 = inverse[2];
float b0 = inverse[3];
float b1 = inverse[4];
float b2 = inverse[5];
float c0 = inverse[6];
float c1 = inverse[7];
float c2 = inverse[8];
#define PT_IN_IMAGE(x,y) (x >= 0 && x < oldImage.width() && y >= 0 && y < oldImage.height())
for (int h = 0; h < returnImage->height(); ++h) {
for (int w = 0; w < returnImage->width(); ++w) {
float x = (a0*w) + (a1*h) + a2;
float y = (b0*w) + (b1*h) + b2;
float w1 = (c0*w) + (c1*h) + c2;
x /= w1;
y /= w1;
if (PT_IN_IMAGE((int)x, (int)y)){ // wh naar xy fix - lars
float x0 = floor(x);
float x1 = ceil(x);
float y0 = floor(y);
float y1 = ceil(y);
float deltaX = (x - x0);
float deltaY = (y - y0);
float p = oldImage.at((int)x0 + .5, (int)y0 + .5).red + (oldImage.at((int)x1 + .5, (int)y0 + .5).red - oldImage.at((int)x0 + .5, (int)y0 + .5).red) * deltaX;
float q = oldImage.at((int)x0 + .5, (int)y1 + .5).red + (oldImage.at((int)x1 + .5, (int)y1 + .5).red - oldImage.at((int)x0 + .5, (int)y1 + .5).red) * deltaX;
returnImage->at(w, h).red = (int)(p + ((q - p)*deltaY));
p = oldImage.at((int)x0 + .5, (int)y0 + .5).green + (oldImage.at((int)x1 + .5, (int)y0 + .5).green - oldImage.at((int)x0 + .5, (int)y0 + .5).green) * deltaX;
q = oldImage.at((int)x0 + .5, (int)y1 + .5).green + (oldImage.at((int)x1 + .5, (int)y1 + .5).green - oldImage.at((int)x0 + .5, (int)y1 + .5).green) * deltaX;
returnImage->at(w, h).green = (int)(p + ((q - p)*deltaY));
p = oldImage.at((int)x0 + .5, (int)y0 + .5).blue + (oldImage.at((int)x1 + .5, (int)y0 + .5).blue - oldImage.at((int)x0 + .5, (int)y0 + .5).blue) * deltaX;
q = oldImage.at((int)x0 + .5, (int)y1 + .5).blue + (oldImage.at((int)x1 + .5, (int)y1 + .5).blue - oldImage.at((int)x0 + .5, (int)y1 + .5).blue) * deltaX;
returnImage->at(w, h).blue = (int)(p + ((q - p)*deltaY));
}
}
}
return returnImage;
}
示例3: convertToGrayscale
ImageGray GrayscaleImage::convertToGrayscale(ImageRGB & image) {
// Image size.
int width = image.width();
int height = image.height();
// The destination image.
ImageGray grayImage(width, height);
// For every pixel in the image.
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
// Get the pixel at position x,y.
Rgb<unsigned char &> pixelRGB = image.at(x, y);
unsigned char& pixelGray = grayImage.at(x, y);
// Convert RGB to grayscale.
pixelGray = pixelRGB.red * 0.114 + pixelRGB.green * 0.587 + pixelRGB.blue * 0.299;
}
}
// Return the gray image.
return grayImage;
}
示例4: if
std::unique_ptr<ImageGray> thresholdDetermination::convert(const ImageRGB& img){
std::unique_ptr<ImageGray> returnImage = std::make_unique<ImageGray>(img.width(), img.height());
meanCorners = (getIntensity(convertToHex(img.at(0, 0).red, img.at(0, 0).green, img.at(0, 0).blue)) + getIntensity(convertToHex(img.at(img.width() - 1, 0).red, img.at(img.width() - 1, 0).green, img.at(img.width() - 1, 0).blue)) + getIntensity(convertToHex(img.at(0, img.height() - 1).red, img.at(0, img.height() - 1).green, img.at(0, img.height() - 1).blue))) + getIntensity(convertToHex(img.at(img.width() - 1, img.height() - 1).red, img.at(img.width() - 1, img.height() - 1).green, img.at(img.width() - 1, img.height() - 1).blue)) / 4;
meanAllOthers = 0;
for (int h = 0; h < img.height(); ++h) {
for (int w = 0; w < img.width(); ++w) {
if (!((w == 0 && h == 0) || (w == img.width() - 1 && h == 0) || (w == 0 && h == img.height() - 1) || (w == img.width() - 1 && h == img.height() - 1))) {
meanAllOthers += getIntensity(convertToHex(img.at(w, h).red, img.at(w, h).green, img.at(w, h).blue));
}
}
}
meanAllOthers /= ((img.width()*img.height()) - 4);
tOld = 0;
tNew = (meanCorners + meanAllOthers) / 2;
unsigned int u1count = 0, u2count = 0;
while (tNew != tOld) {
meanAllOthers = 0;
meanCorners = 0;
for (int h = 0; h < img.height(); ++h) {
for (int w = 0; w < img.width(); ++w) {
if (getIntensity(convertToHex(img.at(w, h).red, img.at(w, h).green, img.at(w, h).blue)) < tNew){
meanCorners += getIntensity(convertToHex(img.at(w, h).red, img.at(w, h).green, img.at(w, h).blue));
u1count++;
}
else if (getIntensity(convertToHex(img.at(w, h).red, img.at(w, h).green, img.at(w, h).blue)) >= tNew){
meanAllOthers += getIntensity(convertToHex(img.at(w, h).red, img.at(w, h).green, img.at(w, h).blue));
u2count++;
}
}
}
if (u1count != 0){
meanCorners /= u1count; // HOTFIX - lars u1count kan nul zijn....
}
if (u2count != 0){
meanAllOthers /= u2count; // HOTFIX - lars u2count kan nul zijn....
}
u1count = 0;
u2count = 0;
tOld = tNew;
tNew = (meanCorners + meanAllOthers) / 2;
}
for (int h = 0; h < returnImage->height(); ++h) {
for (int w = 0; w < returnImage->width(); ++w) {
if (getIntensity(convertToHex(img.at(w, h).red, img.at(w, h).green, img.at(w, h).blue)) < tNew){
returnImage->at(w, h) = 0;
}
else if (getIntensity(convertToHex(img.at(w, h).red, img.at(w, h).green, img.at(w, h).blue)) >= tNew){
returnImage->at(w, h) = 255;
}
}
}
return returnImage;
}