I have an image, and I want to change the color of its background. For example, I want to change the color of the sky from blue to green (or just to pure-white, for simplicity). I have already get the edge of the house, i.e. imgEdges2
(my method of getting the imgEdges2
is very ad-hoc, and any advice for improvement is also welcome), how can I change the color of the sky?
Many thanks!
img = ExampleData[{"TestImage", "House"}]
imgEdges = EdgeDetect[img, 6.7, 0.11];
edgeData = ImageData@imgEdges;
edgeData[[246 ;; 256, All]] = 0;
edgeData[[80 ;; 120, 100 ;; 256]] = 0;
edgeData[[60 ;; 79, 90 ;; 154]] = 0;
edgeData[[50 ;; 59, 90 ;; 110]] = 0;
edgeData[[57 ;; 59, 111 ;; 115]] = 0;
imgEdges2 =Image@edgeData
Manipulate[ColorReplace[#,First@DominantColors@#->rep,d]&@img,{d,0,.1}]
This will more or less work if your background is a solid color and is dominant in the image. You can replace theFirst
with a manual index afterDominantColors
if it's not dominant. TheManipulate
lets you figure out the right thresholding. This doesn't do anything with edge detection or morphological binarization, though—there's certainly more to be done! This gets me this. $\endgroup$