473,327 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

CImg: What is meant by a "pixel value"?

In the CImg library and documentation there are many functions that return "pixel values". I have noticed through experimentation that some pixel values are negative. If I set a pixel to a specific color, is there any way that i can return the exact RGB value of that color? What is a "pixel value" and how is it related to the pixel's actual color?
Feb 3 '10 #1

✓ answered by 69huff

CImg *can* handle png's, using libpng (or ImageMagick, etc).

I don't know if there's a better method to access the pixels values, but, maybe this helps you:

image->atXY(x, y, 0) // this gives you the red channel
image->atXY(x, y, 1) // this gives you the blue channel
image->atXY(x, y, 2) // this gives you the green channel

If someone knows how to get a whole UINT with the ARGB set, please post it. It would be more practical than calling thrice the function, I guess.

Salud!

5 8922
Banfa
9,065 Expert Mod 8TB
Well that rather depends on how you declared your image. Since the class is actually CImg<T>, i.e. a template class, and that template parameter T represents the type of the pixel the pixel value is whatever type you chose to use when you declared your CImg and how that type holds the pixels colour is dependent on what that type is.

Normally pixels are not signed types so the fact you are getting negative values suggests you are declaring it incorrectly. Is just the values used to represent the colour combined together using the bitwise operators to produce a single value.

For example in a Windows bitmap using a RGB colour scheme the pixel is a DWORD (unsigned 32bit value). You can use the RGB macro to combine the a red, green and blue value, each unsigned 8bit values into a single unsigned 32bit pixel COLORREF. The are inverse macros to get the red, green and blue components from a COLORREF.

However you have not said what pixel type you are using so this that example is probably just that, an example that doesn't apply to your situation.
Feb 3 '10 #2
Here's a simple experimental program I have been messing with to try and understand what pixel values are. First I set all the pixels in an image called "img.png" to some random color. Then I read the pixel value using atXY. It seems to always be returning just the red component of the image.
----------------------------------------------------------------------------------------------------
#include <CImg.h>
#include <iostream>

using namespace cimg_library;

using namespace std;

const char colWhite[] = { 255, 255, 255 };

const char colBlack[] = { 0, 0, 0 };
const unsigned char colRand[] = {150, 100, 50};

int main() {
CImg<unsigned int> *image = new CImg<unsigned int>("img.png");
for(int x = 0; x < image->dimx(); ++x) {
for(int y = 0; y < image->dimy(); ++y) {
image->draw_point(x,y,colRand);
}
}

clog << image->atXY(0,0) << "\n";
image->save_png("img");
return 0;
}
----------------------------------------------------------------------------
I've tried changing the rand color values, and from my experience, the atXY function seems to always just return whatever the red value is. Is this actually what is happening here?

Thank you!
Feb 3 '10 #3
Banfa
9,065 Expert Mod 8TB
According to the documentation CImg can not load PNGs
Feb 3 '10 #4
69huff
1
CImg *can* handle png's, using libpng (or ImageMagick, etc).

I don't know if there's a better method to access the pixels values, but, maybe this helps you:

image->atXY(x, y, 0) // this gives you the red channel
image->atXY(x, y, 1) // this gives you the blue channel
image->atXY(x, y, 2) // this gives you the green channel

If someone knows how to get a whole UINT with the ARGB set, please post it. It would be more practical than calling thrice the function, I guess.

Salud!
Feb 12 '10 #5
Whoa! I had no idea about that! That will most definitely help! Thank you so much.
Feb 12 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Russ Perry Jr | last post by:
I'm using "ID" and "Value" in the generic sense here... Let's say one page I had a <html:select> with a collection like this: <html:options collection="items" property="key"...
5
by: johnsuth | last post by:
I want to produce a trivial demonstration of dynamic modification. I thought that pressing a button might change its color. I studied O'Reillys books and successfully created the button with a...
388
by: maniac | last post by:
Hey guys, I'm new here, just a simple question. I'm learning to Program in C, and I was recommended a book called, "Mastering C Pointers", just asking if any of you have read it, and if it's...
1
by: John | last post by:
How can I draw single 1x1 pixel "dot" in window? Not a line, I really mean "dot".
11
by: ajikoe | last post by:
Hello, I used Visual C# Standard Edition. I want to comment my program using xml commentary method, I don't know why if I use value and example tag, it is not working / showed in the html...
2
by: IkBenHet | last post by:
Hello, I am uploading a file using this form in ASP.NET. I have also added a simpel textfield: <form runat="server" enctype="multipart/form-data"> <input type="file" id="oFile" Name="oFile"...
2
by: Boki | last post by:
Hi All, // code start alert("document.all.txtbox"+valueA+".value") // end code could you please advice, can it show the value of txtbox ?
21
by: Steven T. Hatton | last post by:
I'm trying to improve my formal understanding of C++. One significant part of that effort involves clarifying my understanding of the vocabulary used to describe the language. This is from the...
5
by: Diwa | last post by:
Does the "value" type (value as in key-value pair )of "std::map" require a default ctor even if it is not used ? If I comment out Line 1 in the code attached later, i.e remove the default ctor...
1
by: mark | last post by:
Forgive me if this seems like a stupid question but I need help... I'm trying to do a simple online form that emails me the results from a few fields. Here is the code: <form...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.