0

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.

4

1 に答える 1

0

次のようなことができます (言語を指定しませんでした。これは 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;
        }
    }
}

C でもほぼ同じで、三角法と丸めに math.h を使用します。

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;
        }
    }
}
于 2012-08-11T19:37:24.443 に答える