>> img = imread('sky_birds.jpg'); % Load the image >> ndims(img) % Display the number of dimensions ans = 3
Now, each "plane" of the image represents a weighting for a particular color for every pixel. Plane 1 (i.e. img(:,:,1) ) is the red plane, plane 2 (i.e. img(:,:,2) ) is the green plane, and plane 3 (i.e. img(:,:,3) ) is the blue plane. Since your sky is mostly blue, you can try to select the pixels for the sky by picking values in the blue plane that have a high value. With some trial and error, you can select a threshold that helps you select primarily sky pixels:
>> mask = img(:,:,3) > 150; % Find blue values greater than 150
The variable mask is now a 2-D logical matrix with 1 for pixels with high blue values and 0 for pixels with low blue values. Here's what it looks like:
Notice that this also selects pixels on the birds, because the birds are partially white and the color white is composed of high amounts of red, green, and blue.
Now, if you want to set the white pixels in the mask to be white in the image (which they already are for the birds, so no worries), you have to apply the mask to each color plane, setting the mask pixels to a maximum value of 255 (since you are dealing with unsigned 8-bit integers). You can do this by replicating the 2-D mask matrix into a 3-D matrix of the same size as the image matrix:
>> mask3d(:,:,1) = mask; % For the red plane >> mask3d(:,:,2) = mask; % For the green plane >> mask3d(:,:,3) = mask; % For the blue plane
And now you can modify and display your image:
>> img(mask3d) = 255; % Set masked pixels to white >> imshow(img);
This looks very similar to the output you're trying to get.
If you want to learn more about image processing, I strongly suggest checking out Steve Eddins' blog.