I have used the "surf" function to turn a grayscale image into a surface where xy are the original xy coordinate of the image and z is the light intensity at that image. I want to find the curve where this surface intersects with a plane z=(some number). Ideally a function for this curve would be best, but the coordinates of all the pixels would work too. Anybody have an idea of how I can do this?
MATLAB: Intersecting image with plane
surfaces
Related Solutions
Ok, first, the solution set is NOT a line. It is a curve, that lives in the (x,y) plane. Next, There is NO plane of intersection.
Before we try to find any kind of a solution, plot things. How? Use a contour plot. Contour plots are greatly underappreciated things. Another option that is just as good is to use fimplicit, which will give you the same capability.
syms x yf = x + y - x*log(y);
For any real solution to exist, we will need to stay away from negative values of y given the log. What kind of bounds would there be on x? Let me look at a plot first.
fimplicit(fun,[-20,20,0,20]);grid onxlabel Xylabel Y
I would note the importance of a plot here, to help us to realize there are two branches to the solution set. As well, we need to recognize this is an implicit and multi-valued relationship, where for SOME values of x, there are apparently two possible choices for y that satisfy the relation.
Now, it is time to revisit the problem itself. If we have
x*log(y) = x+y
then we can solve for x, as a function of y. Thus
x*(log(y) - 1) = y
and therefore
x = y/(log(y) - 1)
Chose any value for y that is greater than 0, and a single value of x will result. However, we cannot go in the other direction, since there are clearly some values of x that would yield two solutions for y. As well, there are some values for x such that no real solutions exist. Thus for x > 0, but less than roughly 7, there is no real value of y that produces a valid solution.
Sadly, I'm afraid you cannot do something significantly simpler than I have done here. That is the "equation" of the intersection. The equation you want to find is a vaguely hyperbolic thing.
I suppose you could flip the axes.
funy_x = @(y,x) x + y - x.*log(y)fimplicit(funy_x,[0,20,-20,20])xlabel yylabel xgrid on
What else? Where does the singularity lie? That is, what value of y produces a singularity? This is easy. That must arise when
log(y) -1 == 0
or
y = exp(1)
% Planes implicit equations are:
% a1*x + b1*y + c1*z = d1;
% a2*x + b2*y + c2*z = d2;
%
a1 = 256; b1=0; c1=0; d1=0;a2 = 0; b2=0; c2=1; d2=50000;M = [a1, b1, c1; a2, b2, c2];d = null(M); % parallel to cross(M(1,:),M(2,:))
xyz0 = M \ [d1; d2];% Line parametric equation is L(t) = xy0 + t*d, t in R.
Best Answer