Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
1
Task/Image-convolution/C/image-convolution-1.c
Normal file
1
Task/Image-convolution/C/image-convolution-1.c
Normal file
|
|
@ -0,0 +1 @@
|
|||
image filter(image img, double *K, int Ks, double, double);
|
||||
39
Task/Image-convolution/C/image-convolution-2.c
Normal file
39
Task/Image-convolution/C/image-convolution-2.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#include "imglib.h"
|
||||
|
||||
inline static color_component GET_PIXEL_CHECK(image img, int x, int y, int l) {
|
||||
if ( (x<0) || (x >= img->width) || (y<0) || (y >= img->height) ) return 0;
|
||||
return GET_PIXEL(img, x, y)[l];
|
||||
}
|
||||
|
||||
image filter(image im, double *K, int Ks, double divisor, double offset)
|
||||
{
|
||||
image oi;
|
||||
unsigned int ix, iy, l;
|
||||
int kx, ky;
|
||||
double cp[3];
|
||||
|
||||
oi = alloc_img(im->width, im->height);
|
||||
if ( oi != NULL ) {
|
||||
for(ix=0; ix < im->width; ix++) {
|
||||
for(iy=0; iy < im->height; iy++) {
|
||||
cp[0] = cp[1] = cp[2] = 0.0;
|
||||
for(kx=-Ks; kx <= Ks; kx++) {
|
||||
for(ky=-Ks; ky <= Ks; ky++) {
|
||||
for(l=0; l<3; l++)
|
||||
cp[l] += (K[(kx+Ks) +
|
||||
(ky+Ks)*(2*Ks+1)]/divisor) *
|
||||
((double)GET_PIXEL_CHECK(im, ix+kx, iy+ky, l)) + offset;
|
||||
}
|
||||
}
|
||||
for(l=0; l<3; l++)
|
||||
cp[l] = (cp[l]>255.0) ? 255.0 : ((cp[l]<0.0) ? 0.0 : cp[l]) ;
|
||||
put_pixel_unsafe(oi, ix, iy,
|
||||
(color_component)cp[0],
|
||||
(color_component)cp[1],
|
||||
(color_component)cp[2]);
|
||||
}
|
||||
}
|
||||
return oi;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
61
Task/Image-convolution/C/image-convolution-3.c
Normal file
61
Task/Image-convolution/C/image-convolution-3.c
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#include <stdio.h>
|
||||
#include "imglib.h"
|
||||
|
||||
const char *input = "Lenna100.jpg";
|
||||
const char *output = "filtered_lenna%d.ppm";
|
||||
|
||||
double emboss_kernel[3*3] = {
|
||||
-2., -1., 0.,
|
||||
-1., 1., 1.,
|
||||
0., 1., 2.,
|
||||
};
|
||||
|
||||
double sharpen_kernel[3*3] = {
|
||||
-1.0, -1.0, -1.0,
|
||||
-1.0, 9.0, -1.0,
|
||||
-1.0, -1.0, -1.0
|
||||
};
|
||||
double sobel_emboss_kernel[3*3] = {
|
||||
-1., -2., -1.,
|
||||
0., 0., 0.,
|
||||
1., 2., 1.,
|
||||
};
|
||||
double box_blur_kernel[3*3] = {
|
||||
1.0, 1.0, 1.0,
|
||||
1.0, 1.0, 1.0,
|
||||
1.0, 1.0, 1.0,
|
||||
};
|
||||
|
||||
double *filters[4] = {
|
||||
emboss_kernel, sharpen_kernel, sobel_emboss_kernel, box_blur_kernel
|
||||
};
|
||||
const double filter_params[2*4] = {
|
||||
1.0, 0.0,
|
||||
1.0, 0.0,
|
||||
1.0, 0.5,
|
||||
9.0, 0.0
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
image ii, oi;
|
||||
int i;
|
||||
char lennanames[30];
|
||||
|
||||
ii = read_image(input);
|
||||
if ( ii != NULL ) {
|
||||
for(i=0; i<4; i++) {
|
||||
sprintf(lennanames, output, i);
|
||||
oi = filter(ii, filters[i], 1, filter_params[2*i], filter_params[2*i+1]);
|
||||
if ( oi != NULL ) {
|
||||
FILE *outfh = fopen(lennanames, "w");
|
||||
if ( outfh != NULL ) {
|
||||
output_ppm(outfh, oi);
|
||||
fclose(outfh);
|
||||
} else { fprintf(stderr, "out err %s\n", output); }
|
||||
free_img(oi);
|
||||
} else { fprintf(stderr, "err creating img filters %d\n", i); }
|
||||
}
|
||||
free_img(ii);
|
||||
} else { fprintf(stderr, "err reading %s\n", input); }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue