Page 1 of 1

[c++] How to get Image.pixelColor() RGB channels?

Posted: 2019-07-05T18:00:23-07:00
by TheMohawkNinja

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)
        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];


        //Make 30*30 sample space from image
        for(int y=0; y<30; y++)
                for(int x=0; x<30; x++)

                        if(ColorSample[x][y].red()>150 || ColorSample[x][y].green()>150 || ColorSample[x][y].blue()>150)


        return 0;

Re: [c++] How to get Image.pixelColor() RGB channels?

Posted: 2019-07-10T19:06:59-07:00
by TheMohawkNinja
Figured it out. Had to make a "colorRGB" object, Set it's values through GetPixelColor() and then pull the channels by the .red(), .blue(), and .green() methods.