Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Help
»
Graphics
»
getpixel() not assigning the RGBA value properly
Print
Pages: [
1
]
Author
Topic: getpixel() not assigning the RGBA value properly (Read 5143 times)
0 Members and 1 Guest are viewing this topic.
Ajsgolf27
Newbie
Posts: 9
getpixel() not assigning the RGBA value properly
«
on:
June 09, 2014, 09:37:47 pm »
I am trying to add the red pixel values into a vector, but when I print out the vector its empty. The color value prints correctly as the loop goes so its getting the values from the pixels. Also this is extremely slow would there be a better way to do this? I am still a student so any help would be greatly appreciated.
vector
<
Uint8
>
pixelValues
;
x
=
myImage.
getSize
(
)
.
x
;
y
=
myImage.
getSize
(
)
.
y
;
for
(
Uint8 i
=
0
;
i
<
x
;
i
++
)
{
for
(
Uint8 j
=
0
;
j
<
y
;
j
++
)
{
const
Color color
=
myImage.
getPixel
(
i, j
)
;
pixelValues.
push_back
(
(
Uint8
)
color.
r
)
;
cout
<<
(
int
)
color.
r
<<
endl
;
cout
<<
(
int
)
color.
b
<<
endl
;
cout
<<
(
int
)
color.
g
<<
endl
;
cout
<<
"these are red pixels in array "
<<
pixelValues
[
z
++
]
<<
endl
;
}
Logged
Laurent
Administrator
Hero Member
Posts: 32498
Re: getpixel() not assigning the RGBA value properly
«
Reply #1 on:
June 09, 2014, 10:13:42 pm »
You must cast it to int for printing (like you did for the color components), otherwise it will be interpreted as a character.
By the way, don't use Uint8 for i and j, you're uselessly limiting yourself to 255x255 images.
Logged
Laurent Gomila - SFML developer
Ajsgolf27
Newbie
Posts: 9
Re: getpixel() not assigning the RGBA value properly
«
Reply #2 on:
June 09, 2014, 10:26:01 pm »
Thank you! I think this is going to take a really long time would there be a faster way?
Logged
Ixrec
Hero Member
Posts: 1241
Re: getpixel() not assigning the RGBA value properly
«
Reply #3 on:
June 09, 2014, 10:35:44 pm »
Per-pixel processing like this is usually faster on the GPU than the CPU (since that's what GPUs are made for), but since we don't really know what you're trying to do I'm not sure what concrete methods to recommend.
https://stackoverflow.com/questions/3722325/sum-image-intensities-in-gpu
might give a few hints.
Logged
Ajsgolf27
Newbie
Posts: 9
Re: getpixel() not assigning the RGBA value properly
«
Reply #4 on:
June 09, 2014, 11:16:49 pm »
Sorry I didn't specify the goal here but I'm trying to get the red , green and blue values for a set of images and save them to arrays.
Logged
Ixrec
Hero Member
Posts: 1241
Re: getpixel() not assigning the RGBA value properly
«
Reply #5 on:
June 09, 2014, 11:23:09 pm »
That makes it sound like you just want to copy the entire image. When you say "values" do you mean averages or sums or something?
Logged
Jesper Juhl
Hero Member
Posts: 1405
Re: getpixel() not assigning the RGBA value properly
«
Reply #6 on:
June 09, 2014, 11:36:45 pm »
Are you actually looking for this:
sf::RenderWindow::capture
?
Logged
Ajsgolf27
Newbie
Posts: 9
Re: getpixel() not assigning the RGBA value properly
«
Reply #7 on:
June 09, 2014, 11:46:05 pm »
In my loop I went through every pixel in my image and retrieved the red blue and green. I need to do that for every image and from there I need to take the same pixel lets say myImage1[0][0], myImage2[0][0] average them and put into an new array and display the new image
Logged
Ixrec
Hero Member
Posts: 1241
Re: getpixel() not assigning the RGBA value properly
«
Reply #8 on:
June 10, 2014, 12:04:37 am »
I think you can achieve that just by drawing both images to an sf::RenderTexture with the right blend mode and/or transparencies. Look up the tutorial on render textures and the documentation on blend modes (note that custom blend modes have been added since the 2.1 release).
Logged
Ajsgolf27
Newbie
Posts: 9
Re: getpixel() not assigning the RGBA value properly
«
Reply #9 on:
June 10, 2014, 01:19:44 am »
I'm not entirely sure if that will achieve what I am looking for but it's worth a try thanks for you help!
Logged
Ixrec
Hero Member
Posts: 1241
Re: getpixel() not assigning the RGBA value properly
«
Reply #10 on:
June 10, 2014, 07:55:44 am »
If none of the blend modes are quite right, then try using a shader to draw to the render texture. What you want can definitely be done with a very simple shader.
Logged
Print
Pages: [
1
]
SFML community forums
»
Help
»
Graphics
»
getpixel() not assigning the RGBA value properly
anything