How can i remove the sky from this image. (About background removal question)

5 ビュー (過去 30 日間)
Anupong Pittayatornpitak
Anupong Pittayatornpitak 2011 年 2 月 28 日
編集済み: Andrew Newell 2015 年 2 月 22 日
How can i remove the sky from this image.
i must use this following command as guideline to complete this problem. (IMSHOW , IMREAD , ZEROS)
------------------------------------
A = imread('Problem09.jpg');
imshow (A);
but "zeros" how can i use it ?
Someone can guide me how to slove this problem ?
Thanks in advance.

採用された回答

Kenneth Eaton
Kenneth Eaton 2011 年 2 月 28 日

I'm unclear how ZEROS is to be used for this problem, but you could do it with relational operators.

The image is a 3-D RGB (Truecolor) image, which you can see after you load it using IMREAD:

>> 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:

>> imshow(mask);

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.

  1 件のコメント
Anupong Pittayatornpitak
Anupong Pittayatornpitak 2011 年 3 月 1 日
Thank you very much !! ,, I'm understand how to do now. Thanks !!

サインインしてコメントする。

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2011 年 2 月 28 日
I don't see how you would use ZEROS. I might use FALSE AND > OR < AND EDGE.
  1 件のコメント
Anupong Pittayatornpitak
Anupong Pittayatornpitak 2011 年 2 月 28 日
if use FALSE AND > OR < AND EDGE. How can i use it ? Please guide.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by