[c++] How to get Image.pixelColor() RGB channels?
Posted: 2019-07-05T18:00:23-07:00
Hello,
I am trying to write a program that will take a 30*30 sample of an image, but only use pixels that are deemed to be sufficiently saturated. I'm not sure how to check whether the red channel OR green channel OR blue channel are greater than 150.
Current program (the ".red()", ".green()", and ",blue()" bits are something I read online, but g++ throws "no member" errors. I've also tried it with ".quantumRed()" instead of ".red()", but it too throws a "no member" error):
I am trying to write a program that will take a 30*30 sample of an image, but only use pixels that are deemed to be sufficiently saturated. I'm not sure how to check whether the red channel OR green channel OR blue channel are greater than 150.
Current program (the ".red()", ".green()", and ",blue()" bits are something I read online, but g++ throws "no member" errors. I've also tried it with ".quantumRed()" instead of ".red()", but it too throws a "no member" error):
Code: Select all
#include <cstdlib>
#include <Magick++.h>
#include <iostream>
using namespace std;
using namespace Magick;
int main(int argc, char **argv)
{
InitializeMagick(*argv);
Image background("/home/user/Downloads/space1.jpg");
int bgW=background.columns();
int bgH=background.rows();
Image ColorSpace(Geometry(30,30),Color(255,255,255));
Color ColorSample[30][30];
//cout<<"Width="<<bgW<<endl;
//cout<<"Height="<<bgH<<endl;
//Make 30*30 sample space from image
for(int y=0; y<30; y++)
{
for(int x=0; x<30; x++)
{
ColorSample[x][y]=background.pixelColor(((bgW/30)*x),((bgH/30)*y));
//cout<<"Position=("<<((bgW/30)*x)<<","<<((bgH/30)*y)<<")"<<endl;
if(ColorSample[x][y].red()>150 || ColorSample[x][y].green()>150 || ColorSample[x][y].blue()>150)
{
ColorSpace.pixelColor(x,y,ColorSample[x][y]);
}
}
}
ColorSpace.magick("jpg");
ColorSpace.write("ColorSpace.jpg");
return 0;
}