SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Isolating certain color in pictures.

    I'm lookng to try and duplicate a feature found on some cameras, where only certain colors are captured, and the rest is grey.

    I started to write something, I'm only 20 minutes into it, but doos it look to you like it would work?

    PHP Code:
    <?php
    $image 
    $_POST['image'];

    $size = array();

    $size getimagesize($image);

    $width $size[0];
    $length $size[1];

    $width_pixel 1;
    $length_pixel 1;

    $isolation_color $_POST['isolationcolor'];

    while(
    $width_pixel <= $width)
    {
        while(
    $length_pixel <= $length)
        {
            
    $color_index imagecolorat($image$width_pixel$length_pixel);

            
    // make it human readable
            
    $color_array imagecolorsforindex($image$color_index);
            
            
    $red $color_array[red];    
            
    $green $color_array[green];
            
    $blue $color_array[blue];
            
    $y = (0.3x $red) + (0.59 x $green) + (0.11 x $blue); //greyscale values
            
            
    switch ($isolation_color)

            case 
    'blue':
                
                if ((
    $blue 100) && ($green 75) && ($red 75))
                { 
    // leave as is
                
    }
                else
                {
                    
                    
    imagesetpixel($image$width_pixel$length_pixelimagecolorallocate($image$y$y$y);


    // so on and so forth
    The values I used to determine the blue were just off the top of my head, I don't know if that really is blue

  2. #2
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I sort of patched it up, to something I "THINK" will work

    PHP Code:
    <?php
    header
    ('Content-Type: image/jpeg');
    $image imagecreatefromjpeg('/home/dylanb/public_html/whatnow.jpg');
    $size = array();
    $size getimagesize('/home/dylanb/public_html/whatnow.jpg');
    $width $size[0];
    $length $size[1];
    $width_pixel 1;
    $length_pixel 1;
    //$isolation_color = $_POST['isolationcolor'];
    $isolation_color 'blue';
    while(
    $width_pixel <= $width)
    {
        while(
    $length_pixel <= $length)
        {

            
    // make it human readable
    $rgb imagecolorat($image$length_pixel$width_pixel);
    $red = ($rgb >> 16) & 0xFF;
    $green = ($rgb >> 8) & 0xFF;
    $blue $rgb 0xFF;
        
                if ((
    $blue 100) && ($green 75) && ($red 75))
                { 
    // leave as is
                
    }
                else
                {
    $y = (0.3 $red) + (0.59 $green) + (0.11 $blue); //greyscale values
    $grey imagecolorallocate($image$y$y$y);
                    
                    
    imagesetpixel($image$width_pixel$length_pixel$grey);
    $length_pixel++;
    }
    $width_pixel++;
    }}


    imagejpeg($image);
    ?>
    I still get no display, though. No image shows up.

  3. #3
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Man, no one has any idea?


Bookmarks

Posting Permissions

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