int superior( float value);
// Detect edges
void edges(int height, int width, RGBTRIPLE image[height][width])
{
float red_x, green_x, blue_x, red_y ,green_y ,blue_y ;
red_x = green_x = blue_x = red_y = green_y = blue_y = 0.0;
//create a copy of original imgcopy to save original pixel values
RGBTRIPLE imgcopy[height][width];
for (int row = 0; row < height; row++)
{
for (int w = 0; w < width; w++)
{
imgcopy[row][w].rgbtRed = image[row][w].rgbtRed;
imgcopy[row][w].rgbtGreen = image[row][w].rgbtGreen;
imgcopy[row][w].rgbtBlue = image[row][w].rgbtBlue;
}
}
//
for (int row = 0; row < height; row++)
{
for (int col = 0; col < width; col++)
{
//up
if (row > 0)
{
red_y += -2 * imgcopy[row - 1][col].rgbtRed;
green_y += -2 * imgcopy[row - 1][col].rgbtGreen;
blue_y += -2 * imgcopy[row - 1][col].rgbtBlue;
}
//down
if ( row < height -1)
{
red_y += 2 * imgcopy[row + 1][col].rgbtRed ;
green_y += 2 * imgcopy[row + 1][col].rgbtGreen;
blue_y += 2 * imgcopy[row + 1][col].rgbtBlue;
}
//left
if(col > 0)
{
red_x += - 2 * imgcopy[row][col -1].rgbtRed ;
green_x += - 2 * imgcopy[row][col -1].rgbtGreen;
blue_x += - 2 * imgcopy[row][col -1].rgbtBlue;
}
//right
if ( col < width -1)
{
red_x += 2 * imgcopy[row][col + 1].rgbtRed;
green_x += 2 * imgcopy[row][col + 1].rgbtGreen;
blue_x += 2 * imgcopy[row][col + 1].rgbtBlue;
}
//top left
if ( row > 0 && col > 0)
{
red_x += -1 * imgcopy[row -1][col - 1].rgbtRed;
green_x += -1 * imgcopy[row -1][col - 1].rgbtGreen;
blue_x += -1 * imgcopy[row -1][col - 1].rgbtBlue;
red_y += -1 * imgcopy[row - 1][col - 1].rgbtRed ;
green_y += -1 * imgcopy[row - 1][col -1].rgbtGreen;
blue_y += -1 * imgcopy[row - 1][col -1].rgbtBlue;
}
//top right
if ( row > 0 && col < width -1)
{
red_x += 1 * imgcopy[row -1][col + 1].rgbtRed;
green_x += 1 * imgcopy[row -1][col + 1].rgbtGreen;
blue_x += 1 * imgcopy[row -1][col + 1].rgbtBlue;
red_y += -1 * imgcopy[row - 1][col + 1].rgbtRed ;
green_y += -1 * imgcopy[row - 1][col + 1].rgbtGreen;
blue_y += -1 * imgcopy[row - 1][col + 1].rgbtBlue;
}
//bot right
if ( row < height -1 && col < width -1)
{
red_x += 1 * imgcopy[row +1][col + 1].rgbtRed;
green_x += 1 * imgcopy[row +1][col + 1].rgbtGreen;
blue_x += 1 * imgcopy[row +1][col + 1].rgbtBlue;
red_y += 1 * imgcopy[row + 1][col + 1].rgbtRed ;
green_y += 1 * imgcopy[row + 1][col + 1].rgbtGreen;
blue_y += 1 * imgcopy[row + 1][col + 1].rgbtBlue;
}
//bot left
if ( row < height -1 && col > 0)
{
red_x += -1 * imgcopy[row +1][col - 1].rgbtRed;
green_x += -1 * imgcopy[row +1][col - 1].rgbtGreen;
blue_x += -1 * imgcopy[row +1][col -1].rgbtBlue;
red_y += 1 * imgcopy[row + 1][col - 1].rgbtRed ;
green_y += 1 * imgcopy[row + 1][col - 1].rgbtGreen;
blue_y += 1 * imgcopy[row + 1][col - 1].rgbtBlue;
}
image[row][col].rgbtRed = superior(sqrt(( red_x * red_x) + (red_y * red_y)));
image[row][col].rgbtGreen = superior(sqrt(( green_x * green_x )+ (green_y * green_y)));
image[row][col].rgbtBlue = superior( sqrt(( blue_x * blue_x) + (blue_y * blue_y)));
}
}
return;
}
// // //./filter -e images/yard.bmp out.bmp
int superior(float value)
{
int result =0;
if (value > 255)
{
result = 255;
}
else if( value < 0)
{
result =0;
}
else
{
result = round(value);
}
return result;
}
-
Is there a question? Maybe a description of the problem? – Cliff B Dec 14 '20 at 0:12
Add a comment
|
It looks your main issue is not resetting the red_x, green_x, etc values to 0 between iterations.