Dear All;
I have camera fixed in my office which capture image every 5 minute and the captured image sent to MATLAB, what is the best code to detect sun rays that passes through window?
if there is sun rays in office display ('direct sun') else display ('no direct sun')

 Accepted Answer

Image Analyst
Image Analyst on 29 Mar 2020
Edited: Image Analyst on 29 Mar 2020
I'd take an image with the sun in view and then find out how bright it is and it's size. Then threshold the image and look for items roughly that bright and that size.
grayImage = rgb2gray(rgbImage);
binaryImage = grayImage > someValue; % someValue is some value that the sun is ALWAYS brighter than.
[labeledImage, numBlobs] = bwlabel(binaryImage);
props = regionprops(binaryImage, 'Area');
allAreas = [props.Area]
sunBlobs = allAreas >= minAreaForSun & allAreas <= maxAreaForSun;
if sum(sunBlobs) >= 1
% There is a sun in the image.
fprintf('Direct Sun at %s\n', datestr(now));
else
% There is no sun in the image.
fprintf('No Direct Sun at %s\n', datestr(now));
end
Attach photos of "with sun" and "without sun" if you need more help.

7 Comments

thanks for your valued helf
thanks alot for more help.. the first and second images with sun ... the third and fouth without
I thought you were looking out the window and seeing the sun directly. I don't see any sun in any of these photos. Sun is coming in, perhaps directly or perhaps indirectly, but I don't think there is any way to tell, especially when your scene is not fixed. You can still try my code though it will basically find anything that is bright in the image, be it a white paper, the window exposing the outside yard, or some other thing in the room that is brightened by either direct or indirect sunlight coming in. You'd have a better shot if you fixed your camera view point - maybe you could subtract the images.
if the window is selected as the area of interest your code effectivly well be working for direct sun detection....
thank you very much for your support

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!