ultrus Posted August 17, 2011 Share Posted August 17, 2011 Howdy, I have a live image of the sun from SDO (original on left) that I want to incorporate into a design dynamically. In order to do this I need to replace the black background with a blue one (see right image for general idea, created with Photoshop for demo purposes). If I do a simple color replace of black to blue, I get the middle image as a result naturally. This is rather rigid and ugly though, so I need something that will deal with multiple shades and keep as much of the orange/blue combo looking nice as possible. Do you know of a good way to do this using GD or ImageMagick (using Imagick)? So far ImageMagick seems more elegant. Thanks for the feedback in advance. Best regards, Chris Quote Link to comment https://forums.phpfreaks.com/topic/245035-color-replacement-place-sun-from-black-background-to-blue-background/ Share on other sites More sharing options...
JKG Posted August 17, 2011 Share Posted August 17, 2011 with it being black hue and saturate wont work. just use magic wand tool and set the tolerance higher so it grabs out most of the black... along with it will be some of the sun but i can see a way to avoid that. Quote Link to comment https://forums.phpfreaks.com/topic/245035-color-replacement-place-sun-from-black-background-to-blue-background/#findComment-1258606 Share on other sites More sharing options...
ultrus Posted August 17, 2011 Author Share Posted August 17, 2011 I'm not looking to use Photoshop's magic wand tool (I did that for the right image above for demo). I'm looking to use GD or ImageMagick to accomplish this using PHP. I'll be incorporating a live image of the sun into my design (doing this once per hour with Photoshop would kill me). Quote Link to comment https://forums.phpfreaks.com/topic/245035-color-replacement-place-sun-from-black-background-to-blue-background/#findComment-1258622 Share on other sites More sharing options...
JKG Posted August 17, 2011 Share Posted August 17, 2011 oh! sorry, ill look into now, could be interesting. Quote Link to comment https://forums.phpfreaks.com/topic/245035-color-replacement-place-sun-from-black-background-to-blue-background/#findComment-1258627 Share on other sites More sharing options...
ultrus Posted August 17, 2011 Author Share Posted August 17, 2011 So far I'm finding this to be interesting: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $image = new Imagick('latest.jpg'); $clut = new Imagick('hald.png'); $image->clutImage($clut); $image->writeImage('test_out.jpg'); ?> <img src="test_out.jpg" alt="sun" /> Looks TERRIBLE!... but it does use a color lookup table to replace colors. I'm learning more about "hald" and "clut" now... http://www.imagemagick.org/Usage/color_mods/#hald_replacement EDIT: It looks like there's clutImage() and haldClutImage(). Sadly haldClutImage() is not supported on my server (docs say may be svn only). Looking into alternatives... [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/245035-color-replacement-place-sun-from-black-background-to-blue-background/#findComment-1258632 Share on other sites More sharing options...
ultrus Posted August 17, 2011 Author Share Posted August 17, 2011 I got it figured out: SDO Sun Image Moved From Black to Blue Background by ultrus, on Flickr Using clutImage() did wonders. Instead of a 3D Hald Clut image, I used a 2D Clut image to change black to dark blue and gradient after that. See this page for more info on how it all works: http://www.imagemagick.org/Usage/color_mods Best regards, Quote Link to comment https://forums.phpfreaks.com/topic/245035-color-replacement-place-sun-from-black-background-to-blue-background/#findComment-1258697 Share on other sites More sharing options...
xyph Posted August 17, 2011 Share Posted August 17, 2011 Increase contrast until you get a good black and white mask, if possible. Use a feather solution like this http://www.fmwconcepts.com/imagemagick/feather/index.php You should then be able to apply the feathered mask to the image. Not super familiar with imagemagick, so I can't help further at the moment. Keep us updated though, it'll be a very cool function. edit - Wow, that looks great. Quote Link to comment https://forums.phpfreaks.com/topic/245035-color-replacement-place-sun-from-black-background-to-blue-background/#findComment-1258699 Share on other sites More sharing options...
JKG Posted August 17, 2011 Share Posted August 17, 2011 thats an insanely good result. could you post the code? Quote Link to comment https://forums.phpfreaks.com/topic/245035-color-replacement-place-sun-from-black-background-to-blue-background/#findComment-1258703 Share on other sites More sharing options...
xyph Posted August 17, 2011 Share Posted August 17, 2011 With the link he posted, check out the 'Recoloring Images with Lookup Tables' area. It pretty much explains how to do it. His method would run into more issues with a lighter background, in that case, you'd have to use a mask like I was suggesting, and apply the color table based on the mask. Quote Link to comment https://forums.phpfreaks.com/topic/245035-color-replacement-place-sun-from-black-background-to-blue-background/#findComment-1258713 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.