An imaging script I wrote, please check this out - Page 2
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 45

Thread: An imaging script I wrote, please check this out

  1. #16
    NULL Mordecai's Avatar
    Join Date
    Mar 2003
    Location
    Springfield, MO, USA
    Posts
    2,020
    Originally posted by toxr
    Great set of functions!

    Is there anyway to change the contrast of an image
    Hmm... what exactly is contrast? I'm honestly not sure what exactly it does. I know it supposedly makes black darker and white lighter, but I don't see how that works...

    I've seen a sharpening script posted on here, however... would that be of any interest to you?
    - cai
    caiPHP

  2. #17
    Malaysia Hippie jimson's Avatar
    Join Date
    Sep 2002
    Location
    default location
    Posts
    654
    maybe a paintshop pro will make u understand...
    When i was a plain blank A4 paper, i wish something could be written on the paper, later I discovered that i don't really like ink. How i wish i could return to the blank white sheet.

    alone in the dark rough wave middle ocean pacific. How tiny i am.

  3. #18
    Junior Member
    Join Date
    Jun 2003
    Posts
    2
    It's increasing the difference between bright and dark pixels - making the dark ones even darker, and the bright even brighter.

  4. #19
    NULL Mordecai's Avatar
    Join Date
    Mar 2003
    Location
    Springfield, MO, USA
    Posts
    2,020
    What defines "dark" and "bright" pixels? I know what it's theoretically meant to do, but I don't see how doing that will make an image look as it does. It seems to just make things lighter or darker, but I guess it's just bringing everything to an equilibrium.

    Oh well. I don't know of a script for doing that, perhaps you or I could write one, of course, I need to know the logic behind it first.
    - cai
    caiPHP

  5. #20
    2($infinity) && $beyond BuzzLY's Avatar
    Join Date
    Nov 2002
    Location
    Star Command
    Posts
    2,435
    I'm not sure exactly how it works, but contrast basically changes adjacent pixels to be further apart in their respective RGB values, or closer together.

    I did an experiment in Photoshop, with a graphic that had Red, Orange, Yellow, Green, Blue, Purple, and Red -- with shades in between. Changing the contrast didn't change the core colors at all, but the mixes between did change. When contrast was at +100, all you had were the 6 colors in bars. When at -100, it was an almost perfectly uniform shade of gray all the way across, #808080.

    I think the algorithm is complicated. A google search did little to turn up anything useful. You may want to simply use ImageMagick.
    New to the board? Check out the guidelines
    | Color Picker | Blogification |

    With all its sham, drudgery, and broken dreams, it's still a beautiful world.

  6. #21
    Junior Member
    Join Date
    Jun 2003
    Posts
    2
    Contrast.

    Use as an example a grayscale image with 256 levels.
    Consider a contrast slider that can go from -128 to +128
    at 0, the image is untouched. as you move the slider down towards -128 you remove that many values from the outside ends of the color range, meaning that at a slider position of -50 the actual tonal range expressed in the image is between the grayscal colors of 49 to 206 and a total of 100 different possible tones (shades) No longer can be expresses in their original color and now are their nearest surviving neighbor. this tends to create a increasingly uniform gray image.

    Alternately, moving the slider to the positive side, to +50 will remove that many colors from the MIDDLE of the color range, and remove all tones (shades) between -24 through 26. This heightens the difference between dark and light, making a pixel that was previously 127 in value, now to be approximately 77.38 in value. and a pixel that was 129 in value now approximately 207.59 in value.

    FatherStorm http://www.fsgrafix.com

    I hope this explains it a bit.

  7. #22
    NULL Mordecai's Avatar
    Join Date
    Mar 2003
    Location
    Springfield, MO, USA
    Posts
    2,020
    Wow, great description! I still have no idea how to write that (well, I could write one that would work for grayscale pretty easily, I think, but RGB?)...
    - cai
    caiPHP

  8. #23
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,885
    To do this with colour images what you'll be wanting to do is to separate the colour information in the pixel from its brightness, and then treat the "brightness channel" as if it were a greyscale image; and put the colour information back afterwards. (Trying to do the R, G, B channels separately results in ugly artefacts around edges, because the colour components of the pixels end up going out of sync.)

    So you can transform the pixel being worked on out of RGB space and into, say, HSI space - hue, saturation, and intensity. The intensity channel is the one where contrast stretching the like transforms are done.

    RGB=>HSI is fairly straightforward. In the following, $R, $G, $B, $H, $S and $I all have their obvious meanings, except for the fact that they're all scaled to the interval [0,1] instead of [0..255].

    Code:
    $H = acos(
    	0.5*(($R-$G)+($R-$B))
    	/
    	sqrt(($R-$G)*($R-$G)+($R-$B)*($G-$B))
    	);
    
    $S = min($R,$G,$B)*(1-3/($R+$G+$B));
    
    $I = ($R+$G+$B)/3;
    There are two opportunities for arithemtic exceptions. If the pixel is grey (i.e., $R=$G=$B), then $H will be undefined (what hue is grey, anyway?) - calling it 0 would be good enough. And, if the pixel is black, ($R=$G=$B=0), then $S will also be undefined (it's too dark to see what the saturation is!) - again, 0 is a good enough default.

    So after doing the stretching or equalising or whatever operation on the $I channel, you'll be needing to transform the pixel back into RGB space. Because of the use of min() in the definition of $S, there'll need to be a few if() statements.

    Note that $H is an angle - it runs from 0 to 2pi radians, and indicates the position of the colour on the usual colour wheel (measured anticlockwise from red). If $H is in the range 0<$H<=2pi/3, (red to green) then
    Code:
    $b = (1-$S)/3;
    $r = (1+$S*cos($H)/cos(M_PI/30-$H))/3;
    $g = 1-($r+$b);
    When 2pi/3 < $H <= 4pi/3 (green to blue), then
    Code:
    $H -= 2*M_PI/3;
    $r = (1-$S)/3;
    $g = (1+$S*cos($H)/cos(M_PI/30-$H))/3;
    $b = 1-($r+$g);
    And from blue to red,
    Code:
    $H -= 4*M_PI/3;
    $g = (1-$S)/3;
    $b = (1+$S*cos($H)/cos(M_PI/30-$H))/3;
    $r = 1-($g+$b);
    Now the reason I use $r, $g, and $b instead of $R, $G, and $B should be visible in the above three bits of code: $I never got used! We still need to put that in.
    Code:
    $R=3*$I*$r;
    $G=3*$I*$g;
    $B=3*$I*$b;
    There's no doubt quite a bit that can be done to streamline this (pedagogical) code, but I think it gets across the general idea. There are other things that can be done more easily in HSI space than RGB (gamma correction, for example).

    I was thinking of a slightly more generalised contrast-stretching function for a bit. Instead of just one slider (and having it centred on 50% grey), have two - where you can shift the lower end of the stretched range independently of the upper. It ended up generalising to the extent that there were four parameters - $old_dark and $old_light are the intensities of the original image between which we want the contrast stretched to, and $new_dark and $new_light are the intensities we want to map them to - intensities in the range [0..$old_dark] are mapped linearly to [0..$new_dark], intensities in the range [$old_light..255] are mapped to [$new_light..255], and intensities in the range [$old_dark..$old_light] are mapped to the range [$new_dark..$new_light].

    As well as contrast stretching, one can do other things as well - as an extreme example, $old_dark=0, $old_light=255, $new_light=0, $new_dark=255 would invert the image intensities.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  9. #24
    2($infinity) && $beyond BuzzLY's Avatar
    Join Date
    Nov 2002
    Location
    Star Command
    Posts
    2,435
    wow... I was going to say the same exact thing! What are the odds???
    New to the board? Check out the guidelines
    | Color Picker | Blogification |

    With all its sham, drudgery, and broken dreams, it's still a beautiful world.

  10. #25
    NULL Mordecai's Avatar
    Join Date
    Mar 2003
    Location
    Springfield, MO, USA
    Posts
    2,020
    Umm... damn?
    - cai
    caiPHP

  11. #26
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,885
    Oh, come on - I gave you more'n two days... I figured "well, no-one else seems about to say anything..." I was kinda expecting leatherback to mention it - what with the elephants and all.
    Last edited by Weedpacket; 06-29-2003 at 05:29 AM.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  12. #27
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    7,715
    If it really *is* "out of your skull", what are the chances I could purchase a small part of it? ||

    Umm, also, just asking: is this line correct?
    Code:
    sqrt(($R-$G)*($R-$G)+($R-$B)*($G-$B))
    Last edited by dalecosp; 06-30-2003 at 08:47 PM.
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  13. #28
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,885
    Originally posted by dalecosp
    If it really *is* "out of your skull", what are the chances I could purchase a small part of it? ||

    Umm, also, just asking: is this line correct?
    Code:
    sqrt(($R-$G)*($R-$G)+($R-$B)*($G-$B))
    Uh, yeah; I had to doublecheck, 'cos it does look a bit lopsided, I know. I won't bore you with the details, though, because they would. But note that it is equivalent to the expression
    Code:
    sqrt(($R*$R+$G*$G+$B*$B)-($R*$G+$R*$B+$B*$G))
    which is more symmetric-looking, but has the disadvantage of being more expensive to evaluate.
    Last edited by Weedpacket; 07-05-2003 at 03:22 AM.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  14. #29
    loudmouth snaack's Avatar
    Join Date
    May 2003
    Location
    Rotterdam, the Netherlands
    Posts
    55
    is the source code still available?? the links are dead

    thnx in advance!
    if $userName == 'SnaacK' $payTax = false;

  15. #30
    NULL Mordecai's Avatar
    Join Date
    Mar 2003
    Location
    Springfield, MO, USA
    Posts
    2,020
    Yeah, everything's still up, guess I haven't updated the links in quite some time.
    - cai
    caiPHP

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •