How to show what direction an object is facing

18 views (last 30 days)
I'm trying to figure out how to show which direction the slanture of a roof is facing by using image processing, right now I have the roof top traced out for the most part, My first step in isolating the roof was getting a fitted outline by using active contour, then I used both textured filtering with edge detection, and without to get an image of the roof's lines, but what I am really looking for is how to show that the roof is facing north with the edge detection, and how to use that data in the script rather than just showing it as a picture. This is what my final image looks like,
If you have any questions about what I did I would be glad to answer them, but if you have an idea on how to make the image read what directions the roof is facing I would very much appreciate hearing it
P.S., My code if anyone needs to look at it, its not very good but it works kinda, if you have suggestions for the filtering and isolating the roof that would also be helpful. Its also not commented because I am lazy.
%RooftopTracing.M
%Kade_Kneeland
%A script that will read images and locate rooftops through it. The
%script will be the first part of my summer project.
%%Initializes the code
close all
cd roofimages
%loads the picture
imageName = input('Please input the name and extension of the image: ','s');
rooftops = imread(imageName);
imshow(rooftops);
%Gray Scale it
grayImage = rgb2gray(rooftops);
imshow(grayImage);
[r c] = size(grayImage);
switchfactor = grayImage(round(r/2),round(c/2));
if switchfactor <= 120
minimumCanny = .0025;
maximumCanny = .05;
CFval = .6;
elseif switchfactor <= 150
minimumCanny = .005;
maximumCanny = .075;
CFval = .575;
elseif switchfactor <= 180
minimumCanny = .0075;
maximumCanny = .1;
CFval = .55;
elseif switchfactor <= 210
minimumCanny = .01;
maximumCanny = .125;
CFval = .525;
elseif switchfactor <= 240
minimumCanny = .0125;
maximumCanny = .15;
CFval = .5;
else
minimumCanny = .015;
maximumCanny = .2;
end
%%Active Contour (Overlaying mask and Contour) Works
imshow(grayImage);
hold on
mask = false(size(grayImage));
mask(20:end-20,20:end-20) = true;
visboundaries(mask,'Color','b');
bw = activecontour(grayImage, mask, 200, 'edge','ContractionBias',CFval);
visboundaries(bw,'Color','r');
title('Initial contour (blue) and final contour (red)');
figure, imshow(bw)
title('Segmented Image');
%%Reading the Contour and Specifying the roof
bwNew = grayImage;
bwNew(~bw) = 0;
figure;
imshow(bwNew);
E = entropyfilt(bwNew);
Eim = rescale(E);
figure
imshow(Eim)
BW1 = imbinarize(Eim, .9);
imshow(BW1);
gI2 = bwNew;
gI2(BW1) = 0;
imshow(gI2)
BWf1 = edge(gI2,'canny',[minimumCanny, maximumCanny],sqrt(.075));
BWf2 = edge(bwNew,'canny',[minimumCanny, maximumCanny],sqrt(.075));
%BWf2 = edge(gI2,'zerocross',1,[20,100]);
figure;
imshowpair(BWf1,BWf2,'montage')
title('Textured Normal');
  2 Comments
OCDER
OCDER on 7 Aug 2018
No idea what I'm looking at - so it's probably going to be hard to program which direction something is facing. For 2D objects, how are you dealing with optical illusions? The classic illusions : spinning ballerina (which way is she rotating?) and the box (are you looking into or outside of a box?) In your picture, where is "north"?
Kade Kneeland
Kade Kneeland on 7 Aug 2018
Edited: Kade Kneeland on 7 Aug 2018
So the images I am looking at are satellite images of rooftops, so its easy to see what direction the slant is facing in a normal picture, example, this is the grayscale I was working with
Since I am working with the satellite images, the images I collected are in the format so that up is always north. Sorry about the edge detection in my original picture, I need to tune that down a little more. The issue is not what I can see as much as it is what the code can see. I want it to tell me which parts of the roof are facing which direction. Do you have any idea on how to do that?

Sign in to comment.

Accepted Answer

OCDER
OCDER on 7 Aug 2018
Because you're missing "depth" information, it's still very hard to do what you want.
To you, it's a roof and "north" slant seems obvious. But to me, it's a flat field with nice designs, and there is no "north" or even a slant. It's a similar issue with the Necker Cube and ambiguous line drawings.
If you can develop an algorithm to determine which way the Necker cube is facing, then you might be able to make one for your case. Otherwise, you'll need a very complex algorithm to process shadows, guess what is 3D/2D, "assume" roofs are a single color, "assume" no solar panels on the roof, etc.
Perhaps look up in the search engine how the tech companies convert satellite images into 3D globe maps. The 3D depth information is critical to do what you want. Here's a cool example, but this definitely took a lot of time and many people:
  1 Comment
Kade Kneeland
Kade Kneeland on 7 Aug 2018
Thank you for your help, although I was looking for a way to use the satelliye 2D images because of how I have my code set up, I will keep this in mind and will likely change my script to include depth information using Google earth, as soon as I figure out how to do that, I know it can be done. I'm going to leave the question unanswered to see if anyone else has an idea, but thank you for the most likely answer. If no one else answers in a week, I'll set this as the answer

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!