Question

Instead of scanning the pixels row by row , I am trying to scan the pixels from the origin or any arbitrary point in the image at an angle say 10' ,then incrementing angle in steps of 10' upto 360' ,i want to access the pixels falling in the line at each angle and do some processing..

pls help me out with how to access pixel values lying at a particular angle from the origin or any point in the image.

Was it helpful?

Solution

You can do something like this (you didn't specify language, this is in java):

bool[][] processedPixels = new bool[width][height]; // To avoid processing the same pixel twice

for(int deg = 0; deg < 360; deg+=10)
{
    double angle = Math.toRadians(deg);
    for(int r = 0; r < maxRadius; r++)
    {
        int x = originX + (int) Math.round(r * Math.cos(angle));
            int y = originY + (int) Math.round(r * Math.sin(angle));

        if(!processedPixels[x][y])
        {       
            processPixel(x,y);
            processedPixels[x][y] = true;
        }
    }
}

In C, it would be almost the same, use math.h for the trigonometry and rounding:

include <math.h>
#define PI 3.14159 // use the accuracy you need
#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * PI)


int deg;
double rad;
int processedPixels[width][height] = {0};

for(deg = 0; deg < 360; deg+=10)
{
    int r;
    rad = DEGREES_TO_RADIANS(deg);
    for(r = 0; r < maxRadius; r++)
    {
        int x,y;
        x = originX + (int) round(r * cos(rad));
        y = originY + (int) round(r * sin(rad);

        if(processedPixels[x][y] == 0)
        {       
            processPixel(x,y);
            processedPixels[x][y] = 1;
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top