# how can i detect sky

5 views (last 30 days)
Eren Aslan on 29 Mar 2022
Commented: Adam Danz on 30 Mar 2022
Hello
I want to detect sky in a image and chang it colour to black.How can i do that?
For example this image:
Adam Danz on 29 Mar 2022
Edited: Adam Danz on 29 Mar 2022
@Eren Aslan for your simple image of a nearly uniform background, I would start with regionprops to segment the plane and then assume everything else is sky (including the ocean in my image above). However, it will not work with more complex backgrounds.
Sam Chak on 29 Mar 2022
@Eren Aslan Are you trying to develop the MATLAB-based "Magic Wand"? Sound like an interesting project!

yanqi liu on 30 Mar 2022
yes，sir，for more image，may be use DeepLearning to segment
but just for this image，we can use some simple method，such as
jm = rgb2lab(im);
s = imcomplement(mat2gray(jm(:,:,3)));
bw = im2bw(s, graythresh(s));
im2 = im;
% make sky to black
r = im2(:,:,1);g = im2(:,:,2);b = im2(:,:,3);
r(bw) = 0; g(bw) = 0; b(bw) = 0;
im2 = cat(3,r,g,b);
figure;
subplot(2,2,1); imshow(im,[]);
subplot(2,2,2); imshow(s,[]);
subplot(2,2,3); imshow(bw,[]);
subplot(2,2,4); imshow(im2,[]);
Adam Danz on 30 Mar 2022
Nice work!