Thread: Graphing a direction field and intensity map

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    5

    Graphing a direction field and intensity map

    Hello, I'm doing an assignment where I need to create a slope/direction field and an intensity map for a given function. I have no problems getting my data, that was quite simple, I have an image that I turn into a matrix and then I use the matrix to do various calculations. What I basically have right now is a results matrix that is split with elements in columns as follows:

    Pixels
    pixel x (column in image)
    pixel y (row in image)

    Vector components (i, j, k)
    normal i
    normal j
    normal k

    Illumination values (percentages)
    Illumination Source 1
    Illumination Source 2
    Illumination Source 3

    So essentially I have a table where you look at your given xy-coordinate and this corresponds to a vector in 3D space, which has a certain intensity value (illumination). The intensity value is for a grayscale image from 0-255, where 255 is the brightest (white) and 0 is the darkest (black). What I'm trying to do now is first take my original image matrix and based on the slope create by the components at (normal i, normal j) I will create a short slope field for that given pixel. Then I want to use the normal i, normal j data to create an intensity map where I will plot (i,j) and then it will be assigned in an intensity.

    To give an idea of the intensity map I did a quick search and this is bassically what I want to do: Intensity Map
    So my (i,j) will be given a gray value from the illumination source (I can easily do that), I just need help in figuring out how to create these graphs/images.

    For the direction field I am essentially looking to create an image like this: Slope Field

    I come from a different programming background (MATLAB) so this all boils down to syntax issues and knowledge of C++ functions and libraries (those I do not know so well).

    I'll post some sample code of the loop I've used to create my data table. Bear with crazy coding.
    Code:
    for (int y7 = 0; y7 < in->width; y7++) // Row (y-value)
    {
    	for (int x7 = 0; x7 < in->height; x7++) // Column (x-value)
    	{
    		if (All_Sphere[y7][x7] == 255)
    		{
    			Counta = Counta + 1;
    			Normal[0][0] = 2 * (Centroid[0][0] - x7);
    			Normal[0][1] = 2 * (Centroid[0][0] - y7);
    			Normal[0][3] = 2 * sqrt(Radius^2 - (Centroid[0][0] - x7)^2 - (Centroid[0][0] - y7)^2);
    			Albedo = sqrt(Normal[0][0]*Normal[0][0] + Normal[0][1]*Normal[0][1] + Normal[0][2]*Normal[0][2]);
    			Normal[0][0] = Normal[0][0]/Albedo;
    			Normal[0][1] = Normal[0][1]/Albedo;
    			Normal[0][2] = Normal[0][2]/Albedo;
    			Ill_1 = (Normal[0][0]*I_SphereVn_1[0][0] (some long code);
    			Ill_2 = (Normal[0][0]*I_SphereVn_2[0][0] (some long code);
    			Ill_3 = (Normal[0][0]*I_SphereVn_3[0][0] (some long code);
    			Table_Sphere_All[Counta][0] = x7;
    			Table_Sphere_All[Counta][1] = y7;
    			Table_Sphere_All[Counta][2] = Normal[0][0];
    			Table_Sphere_All[Counta][3] = Normal[0][1];
    			Table_Sphere_All[Counta][4] = Normal[0][2];
    			Table_Sphere_All[Counta][5] = Ill_1;
    			Table_Sphere_All[Counta][6] = Ill_2;
    			Table_Sphere_All[Counta][7] = Ill_3;
    		}
    	}
    }
    So I can find the slope at each pixel and my loop would look something like this:
    Code:
    // Needle Map
    
    double Slope;
    
    for (int i = 0; i < Count; i++)
    {
    	Table_Sphere_All[i][0]; // x-value
    	Table_Sphere_All[i][1]; // y-value
    	// I need to Plot these points 
    	
    	Slope = Table_Sphere_All[i][3] / Table_Sphere_All[i][3];
    	// Now using this slope, I make a small line at the point, but I'm 
            // not sure how I can do this.
    
    	// I thought that I could take the value of my pixel and then 
    	// subtract 0.1 (get a point), add 0.1 (get a point) and then 
    	// have a small plot at each point, and you make slopes that 
    	// way.  I just need help figuring out how to graph this
    	Graph 1;
    }
    Code:
    // Intensity Map (I know they can be in the same loop, but separate for this explanation.)
    
    int Intensity1; // Will int truncate the value?  I would rather have it round the values to an integer.
    int Intensity2;
    int Intensity3;
    
    for (int i = 0; i < Count; i++)
    {
    	Table_Sphere_All[i][2]; // normal i
    	Table_Sphere_All[i][3]; // normal j
    	// I need to Plot these points and assign a gray value to them.
    	
    	Intensity1 = Table_Sphere_All[i][5]*255;
    	Intensity2 = Table_Sphere_All[i][6]*255;
    	Intensity3 = Table_Sphere_All[i][7]*255;
    	
    	// Then for my plotted value I assign my intensity, so:
    	Point(normal i, normal j) = Intensity1; // Graph 1
    	Point(normal i, normal j) = Intensity2; // Graph 2
    	Point(normal i, normal j) = Intensity3; // Graph 3
    	
    	// So now I will put this value on the graph.
    	Graph 2 // Intensity 1, since the slope field graph 1, I use graph 2
    	Graph 3 // Intensity 2
    	Graph 4 // Intensity 3
    }
    And then I want to output these graphs, I think I can get that, I just need to figure out how to plot this.

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I have no idea why you are going through all of that.

    If you want to multiply a vector by a matrix then you are doing way too much stuff.

    Compute your matrix. Treat your points as 3D vectors. Multiply the vectors by the matrix thus transforming them into the correct coordinate space. Plot the transformed coordinate.

    A slope graph can be accomplished using a Sobel filter on x and y. The normal map can be computed by multiplying the vertex normal by pure white or 255,255,255 (Normalized: 1.0f,1.0f,1.0f). This means that white would indicate a normal of 1.0f,1.0f,1.0f.
    Last edited by VirtualAce; 11-29-2004 at 11:04 PM.

Popular pages Recent additions subscribe to a feed