continued working on the pipes part
This commit is contained in:
parent
0cc2998922
commit
04e67b26b7
|
@ -6,103 +6,83 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
struct image_t *S1_smoothen(struct image_t *input_image)
|
||||
float *S1_smoothen(struct image_t *input_image, float *smooth)
|
||||
{
|
||||
// cout << input_image->width << input_image->height << " " << input_image->image_pixels << endl;
|
||||
int width = input_image->width;
|
||||
int height = input_image->height;
|
||||
|
||||
// memory allocation
|
||||
struct image_t *smoother = new struct image_t;
|
||||
smoother->height = height;
|
||||
smoother->width = width;
|
||||
smoother->image_pixels = new uint8_t **[height];
|
||||
long ind = 0;
|
||||
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
smoother->image_pixels[i] = new uint8_t *[width];
|
||||
for (int j = 0; j < width; j++)
|
||||
smoother->image_pixels[i][j] = new uint8_t[3];
|
||||
}
|
||||
|
||||
for (int i = 1; i < height - 1; i++)
|
||||
{
|
||||
for (int j = 1; j < width - 1; j++)
|
||||
{
|
||||
for (int k = 0; k < 3; k++)
|
||||
{
|
||||
// image->image_pixels[i][j][k] = val;
|
||||
// edge cases
|
||||
if (i == 0 && j == 0)
|
||||
{ // i-1 and j - 1 doesnt exist
|
||||
smoother->image_pixels[i][j][k] = (input_image->image_pixels[i][j][k] / 4 + input_image->image_pixels[i][j + 1][k] / 4 + input_image->image_pixels[i + 1][j][k] / 4 + input_image->image_pixels[i + 1][j + 1][k] / 4);
|
||||
smooth[ind] = (float)(input_image->image_pixels[i][j][k] / 4 + input_image->image_pixels[i][j + 1][k] / 4 + input_image->image_pixels[i + 1][j][k] / 4 + input_image->image_pixels[i + 1][j + 1][k] / 4);
|
||||
}
|
||||
else if (i == height - 1 && j == 0)
|
||||
{ // i+1 and j-1 does not exist
|
||||
smoother->image_pixels[i][j][k] = (input_image->image_pixels[i - 1][j][k] / 4 + input_image->image_pixels[i - 1][j + 1][k] / 4 + input_image->image_pixels[i][j][k] / 4 + input_image->image_pixels[i][j + 1][k] / 4);
|
||||
smooth[ind] = (float)(input_image->image_pixels[i - 1][j][k] / 4 + input_image->image_pixels[i - 1][j + 1][k] / 4 + input_image->image_pixels[i][j][k] / 4 + input_image->image_pixels[i][j + 1][k] / 4);
|
||||
}
|
||||
|
||||
else if (i == 0 && j == width - 1)
|
||||
{ // i-1 and j+1 does not exist
|
||||
smoother->image_pixels[i][j][k] = (input_image->image_pixels[i][j - 1][k] / 4 + input_image->image_pixels[i][j][k] / 4 + input_image->image_pixels[i + 1][j - 1][k] / 4 + input_image->image_pixels[i + 1][j][k] / 4);
|
||||
smooth[ind] = (float)(input_image->image_pixels[i][j - 1][k] / 4 + input_image->image_pixels[i][j][k] / 4 + input_image->image_pixels[i + 1][j - 1][k] / 4 + input_image->image_pixels[i + 1][j][k] / 4);
|
||||
}
|
||||
else if (i == height - 1 && j == width - 1)
|
||||
{ // i+1 and j+1 does not exist
|
||||
smoother->image_pixels[i][j][k] = (input_image->image_pixels[i - 1][j - 1][k] / 4 + input_image->image_pixels[i - 1][j][k] / 4 + input_image->image_pixels[i][j - 1][k] / 4 + input_image->image_pixels[i][j][k] / 4);
|
||||
smooth[ind] = (float)(input_image->image_pixels[i - 1][j - 1][k] / 4 + input_image->image_pixels[i - 1][j][k] / 4 + input_image->image_pixels[i][j - 1][k] / 4 + input_image->image_pixels[i][j][k] / 4);
|
||||
}
|
||||
else if (i == 0)
|
||||
{ // i - 1 does not exist
|
||||
smoother->image_pixels[i][j][k] = (input_image->image_pixels[i][j - 1][k] / 6 + input_image->image_pixels[i][j][k] / 6 + input_image->image_pixels[i][j + 1][k] / 6 + input_image->image_pixels[i + 1][j - 1][k] / 6 + input_image->image_pixels[i + 1][j][k] / 6 + input_image->image_pixels[i + 1][j + 1][k] / 6);
|
||||
smooth[ind] = (float)(input_image->image_pixels[i][j - 1][k] / 6 + input_image->image_pixels[i][j][k] / 6 + input_image->image_pixels[i][j + 1][k] / 6 + input_image->image_pixels[i + 1][j - 1][k] / 6 + input_image->image_pixels[i + 1][j][k] / 6 + input_image->image_pixels[i + 1][j + 1][k] / 6);
|
||||
}
|
||||
|
||||
else if (j == 0)
|
||||
{ // j -1 does not exist
|
||||
smoother->image_pixels[i][j][k] = (input_image->image_pixels[i - 1][j][k] / 6 + input_image->image_pixels[i - 1][j + 1][k] / 6 + input_image->image_pixels[i][j][k] / 6 + input_image->image_pixels[i][j + 1][k] / 6 + input_image->image_pixels[i + 1][j][k] / 6 + input_image->image_pixels[i + 1][j + 1][k] / 6);
|
||||
smooth[ind] = (float)(input_image->image_pixels[i - 1][j][k] / 6 + input_image->image_pixels[i - 1][j + 1][k] / 6 + input_image->image_pixels[i][j][k] / 6 + input_image->image_pixels[i][j + 1][k] / 6 + input_image->image_pixels[i + 1][j][k] / 6 + input_image->image_pixels[i + 1][j + 1][k] / 6);
|
||||
}
|
||||
|
||||
else if (i == height - 1)
|
||||
{ // i+1 does not exist
|
||||
smoother->image_pixels[i][j][k] = (input_image->image_pixels[i - 1][j - 1][k] / 6 + input_image->image_pixels[i - 1][j][k] / 6 + input_image->image_pixels[i - 1][j + 1][k] / 6 + input_image->image_pixels[i][j - 1][k] / 6 + input_image->image_pixels[i][j][k] / 6 + input_image->image_pixels[i][j + 1][k] / 6);
|
||||
smooth[ind] = (float)(input_image->image_pixels[i - 1][j - 1][k] / 6 + input_image->image_pixels[i - 1][j][k] / 6 + input_image->image_pixels[i - 1][j + 1][k] / 6 + input_image->image_pixels[i][j - 1][k] / 6 + input_image->image_pixels[i][j][k] / 6 + input_image->image_pixels[i][j + 1][k] / 6);
|
||||
}
|
||||
else if (j == width - 1)
|
||||
{ // j + 1 does not exist
|
||||
smoother->image_pixels[i][j][k] = (input_image->image_pixels[i - 1][j - 1][k] / 6 + input_image->image_pixels[i - 1][j][k] / 6 + input_image->image_pixels[i][j - 1][k] / 6 + input_image->image_pixels[i][j][k] / 6 + input_image->image_pixels[i + 1][j - 1][k] / 6 + input_image->image_pixels[i + 1][j][k] / 6);
|
||||
smooth[ind] = (float)(input_image->image_pixels[i - 1][j - 1][k] / 6 + input_image->image_pixels[i - 1][j][k] / 6 + input_image->image_pixels[i][j - 1][k] / 6 + input_image->image_pixels[i][j][k] / 6 + input_image->image_pixels[i + 1][j - 1][k] / 6 + input_image->image_pixels[i + 1][j][k] / 6);
|
||||
}
|
||||
else
|
||||
{
|
||||
smoother->image_pixels[i][j][k] = (input_image->image_pixels[i - 1][j - 1][k] / 9 + input_image->image_pixels[i - 1][j][k] / 9 + input_image->image_pixels[i - 1][j + 1][k] / 9 + input_image->image_pixels[i][j - 1][k] / 9 + input_image->image_pixels[i][j][k] / 9 + input_image->image_pixels[i][j + 1][k] / 9 + input_image->image_pixels[i + 1][j - 1][k] / 9 + input_image->image_pixels[i + 1][j][k] / 9 + input_image->image_pixels[i + 1][j + 1][k] / 9);
|
||||
smooth[ind] = (float)(input_image->image_pixels[i - 1][j - 1][k] / 9 + input_image->image_pixels[i - 1][j][k] / 9 + input_image->image_pixels[i - 1][j + 1][k] / 9 + input_image->image_pixels[i][j - 1][k] / 9 + input_image->image_pixels[i][j][k] / 9 + input_image->image_pixels[i][j + 1][k] / 9 + input_image->image_pixels[i + 1][j - 1][k] / 9 + input_image->image_pixels[i + 1][j][k] / 9 + input_image->image_pixels[i + 1][j + 1][k] / 9);
|
||||
}
|
||||
ind++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return smoother;
|
||||
return smooth;
|
||||
}
|
||||
|
||||
struct image_t *S2_find_details(struct image_t *input_image, struct image_t *smoothened_image)
|
||||
float *S2_find_details(struct image_t *input_image, float *smoothened_image)
|
||||
{
|
||||
// TODO
|
||||
int width = input_image->width;
|
||||
int height = input_image->height;
|
||||
|
||||
struct image_t *details = new struct image_t;
|
||||
details->height = height;
|
||||
details->width = width;
|
||||
details->image_pixels = new uint8_t **[height];
|
||||
float *details = (float *)malloc(height * width * 3 * sizeof(float));
|
||||
long ind = 0;
|
||||
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
details->image_pixels[i] = new uint8_t *[width];
|
||||
for (int j = 0; j < width; j++)
|
||||
details->image_pixels[i][j] = new uint8_t[3];
|
||||
}
|
||||
|
||||
for (int i = 1; i < height - 1; i++)
|
||||
{
|
||||
for (int j = 1; j < width - 1; j++)
|
||||
{
|
||||
for (int k = 0; k < 3; k++)
|
||||
{
|
||||
details->image_pixels[i][j][k] = max(0, input_image->image_pixels[i][j][k] - smoothened_image->image_pixels[i][j][k]);
|
||||
details[ind] = max((float)0, (float)input_image->image_pixels[i][j][k] - smoothened_image[ind]);
|
||||
ind++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,33 +90,25 @@ struct image_t *S2_find_details(struct image_t *input_image, struct image_t *smo
|
|||
return details;
|
||||
}
|
||||
|
||||
struct image_t *S3_sharpen(struct image_t *input_image, struct image_t *details_image)
|
||||
float *S3_sharpen(struct image_t *input_image, float *details_image)
|
||||
{
|
||||
// TODO
|
||||
int width = input_image->width;
|
||||
int height = input_image->height;
|
||||
|
||||
int a = 1;
|
||||
float a = 1;
|
||||
|
||||
struct image_t *sharp = new struct image_t;
|
||||
sharp->height = height;
|
||||
sharp->width = width;
|
||||
sharp->image_pixels = new uint8_t **[height];
|
||||
float *sharp = (float *)malloc(height * width * 3 * sizeof(float));
|
||||
|
||||
long ind = 0;
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
sharp->image_pixels[i] = new uint8_t *[width];
|
||||
for (int j = 0; j < width; j++)
|
||||
sharp->image_pixels[i][j] = new uint8_t[3];
|
||||
}
|
||||
|
||||
for (int i = 1; i < height - 1; i++)
|
||||
{
|
||||
for (int j = 1; j < width - 1; j++)
|
||||
{
|
||||
for (int k = 0; k < 3; k++)
|
||||
{
|
||||
sharp->image_pixels[i][j][k] = min(255, input_image->image_pixels[i][j][k] + details_image->image_pixels[i][j][k]) * a;
|
||||
sharp[ind] = min((float)255, (float)input_image->image_pixels[i][j][k] + details_image[ind]);
|
||||
ind++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue