Load Image and do Histogram equalization using SDL

Hi everyone, I really a novice in SDL coding and would need help from any professionals that could show me how its done. I want to load a image (I have found the load image example code) and do histogram equalization (which i have no idea how to implement it using SDL). So the final output would be an equalized image displayed on the SDL surface window.

Any pros can kindly show me how its done ?

Clueless here… [Crying or Very sad] :?

I don’t think anyone here is going to be in a rush to do your CSCI366 assignment 2 for you :slight_smile:

yeah… I dont know how to implement. And i dont know why I paid for school to get taught on my own. The assignments for 366 is as good as saying "you know abcdefghijkl, now find out the others that complete the entire alphabet chain. GOODLUCK. " … crap…

It’s more like “We give you the brick, now build the wall.” but maybe we don’t have the same conception of the school.

Maybe if you tell us were you’re stuck, we could better help you.
Do you have trouble to understand the histogram equalization algorithm, to apply it using SDL_Surface or to find one of the exemple available on google ?

I can’t help you with the ‘histogram’ part, sorry about that :-).

I wonder why you choose SDL for this classwork. Although it’s not a bad choice, it’s a little bit harder comparing using other platform/api (eg. .Net).

Anyway, here’s a little help I could give. you can load the image file into a surface (using SDL_image if you wish), and then lock the surface. At this point you have raw image data, translate it into an array of color/pixel (this part is a little tricky depending on the pixel format you’re using). Once you have the array of pixel, you can process it anyway you like :-).

I’d also suggest you to do a research on how the image data is constructed, things like raw data, width, height, pitch, pixel format, etc.

Again, sorry, no code here, but it should not be too hard to implement. Try your best, and if you stuck feel free to ask.

OpenCV can do image histograms, if that’s what you’re after, and you’re
okay with using C++.
You could use SDL and OpenCV side by side (I have done that in past
projects), but you’ll probably find that OpenCV will handle all your issues
(displaying the image/histogram, basic keyboard, etc.)

There are probably other options available to you, too, but I know for sure
OpenCV can help you with that, but since this does sound like homework, I
definitely can’t give you details on how to do it.On Sat, May 10, 2014 at 6:59 PM, mr_tawan <mr_tawan at hotmail.com> wrote:

I can’t help you with the ‘histogram’ part, sorry about that [image:
Smile].

I wonder why you choose SDL for this classwork. Although it’s not a bad
choice, it’s a little bit harder comparing using other platform/api (eg.
.Net).

Anyway, here’s a little help I could give. you can load the image file
into a surface (using SDL_image if you wish), and then lock the surface. At
this point you have raw image data, translate it into an array of
color/pixel (this part is a little tricky depending on the pixel format
you’re using). Once you have the array of pixel, you can process it anyway
you like [image: Smile].

I’d also suggest you to do a research on how the image data is
constructed, things like raw data, width, height, pitch, pixel format, etc.

Again, sorry, no code here, but it should not be too hard to implement.
Try your best, and if you stuck feel free to ask.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Using SDLv2, image data is already guaranteed to be in one of a
handful of “sane” formats. Under SDLv1, it generally was but was
never guaranteed to be. These days you can use something like
SDL_PIXELFORMAT_RGB888 and know that is what you’re getting. And
if it’s not absolutely timing-critical (such as startup), you can
convert the surface to such a format so that you KNOW what you’re
dealing with.

Or you can use SDL_GetRGB (IIRC) to read the RGB values of each pixel
not knowing or caring what format SDL gave you. This would be my
suggestion. The headers you’re going to want to look at are
SDL_surface.h and SDL_pixels.h.

As to the histogram generation, I assume that’s the purpose of the
assignment: To figure out how to do that, and demonstrate that you
can.

JosephOn Sat, May 10, 2014 at 10:59:43PM +0000, mr_tawan wrote:

I can’t help you with the ‘histogram’ part, sorry about that :-).

I wonder why you choose SDL for this classwork. Although it’s not a bad choice, it’s a little bit harder comparing using other platform/api (eg. .Net).

Anyway, here’s a little help I could give. you can load the image file into a surface (using SDL_image if you wish), and then lock the surface. At this point you have raw image data, translate it into an array of color/pixel (this part is a little tricky depending on the pixel format you’re using). Once you have the array of pixel, you can process it anyway you like :-).

I’d also suggest you to do a research on how the image data is constructed, things like raw data, width, height, pitch, pixel format, etc.

Again, sorry, no code here, but it should not be too hard to implement. Try your best, and if you stuck feel free to ask.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I’ve been off the list for awhile and didn’t get all the previous messages in
this thread, hence I don’t know the purpose of your histogram.

If you’re familiar with LaTeX, I may be able to help. I’ve written C code that
takes raw data from a text file and generates a .tex file with a histogram of
the data. It’s purpose is very specific though and may not suit your needs.

The data it processes is a list of student grades, and the purpose is to
generate a histogram of grade spread. If that would be useful to you, please
email me off list.

JeffOn Saturday 10 May 2014 16:48:41 T. Joseph Carter wrote:

As to the histogram generation, I assume that’s the purpose of the
assignment: To figure out how to do that, and demonstrate that you
can.

Joseph


“Women don’t want to hear what you think.
Women want to hear what they think - in a deeper voice.”
–Bill Cosby

zaviersoul wrote:

yeah… I dont know how to implement. And i dont know why I paid for school to get taught on my own. The assignments for 366 is as good as saying "you know abcdefghijkl, now find out the others that complete the entire alphabet chain. GOODLUCK. " … crap…

It’s a really tough class. The programming part of things is a few levels of abstraction away from what we are learning. I have not finished the assignment properly -I am having trouble with my putPixel function …which for some reason gives me a greyscale image with vertical lines in it.

Anyways -to help you.

Load the image onto an SDL_Surface.
Scan through the image inside nested for loops and read the *Surface->pixels data into an array or something.
Bit shift the RGB components out of each colour.
Generate a histogram for each colour.
Perform the histogram equalisation (there are some good Youtube tutorials on this).
Create new pixel values with your equalised data.
Bit shift them back from Uint8 into Uint32 so they become ‘pixels’ again.
Draw the new image.

THanks for all the help peeps!