How to show what direction an object is facing
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
OCDER
2018-8-7
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"?
采纳的回答
OCDER
2018-8-7
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:
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!