Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define STB_IMAGE_IMPLEMENTATION
- #include "stb/stb_image.h"
- #define STB_IMAGE_WRITE_IMPLEMENTATION
- #include "stb/stb_image_write.h"
- unsigned char filter[] = {1,2,1,
- 2,4,2,
- 1,2,1
- };
- using namespace std;
- unsigned char* makeStuff(unsigned char *img, int w,int h, int ch)
- {
- size_t s = (w)*(h)*ch;
- unsigned char *res = (unsigned char *)malloc(s);
- unsigned char p1,p2,p3,p4,p5,p6,p7,p8,p9;
- for(int x=1; x<h; x++)
- {
- for(int y=1; y<w; y++)
- {
- for(int c=0; c<ch; c++)
- {
- p1 = (img[ch*( (x-1) *w + (y-1)) +c]*filter[0]);
- p2 = (img[ch*( (x) *w + (y-1)) +c]*filter[1]);
- p3 = (img[ch*( (x+1) *w + (y-1)) +c]*filter[2]);
- p4 = (img[ch*( (x-1) *w + (y)) +c]*filter[3]);
- p5 = (img[ch*( (x) *w + (y)) +c]*filter[4]);
- p6 = (img[ch*( (x+1) *w + (y)) +c]*filter[5]);
- p7 = (img[ch*( (x-1) *w + (y+1)) +c]*filter[6]);
- p8 = (img[ch*( (x) *w + (y+1)) +c]*filter[7]);
- p9 = (img[ch*( (x+1) *w + (y+1)) +c]*filter[8]);
- res[ch*(x*w+y)+c] = ((p1+p2+p3+p4+p5+p6+p7+p8+p9))/16;
- }
- }
- }
- return res;
- }
- int main()
- {
- string path = "t.jpg";
- int w,h,ch,gch;
- unsigned char *image = stbi_load(path.c_str(),&w,&h,&ch,0);
- unsigned char *im = makeStuff(image,w,h,ch);
- stbi_write_jpg("t2.jpg",w,h,ch,im,100);
- stbi_image_free(image);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement