I have two images. I like to consider the 1st pixel of image 1 and 1st pixel of image 2. Add those pixel and divide by 2. So, basically I try to find out the average of pixels. I like to find out average for every pixel. Taking those averages I like to create a new image. I implemented the code in C.
My code block
#include <stdio.h>
#include <stdlib.h>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
int main() {
int width1, height1, channels1,width2, height2, channels2;
int i, new_width, new_height,j;
//read image using stbi_load function
unsigned char *apple = stbi_load("apple.jpg", &width1, &height1, &channels1, 0);
unsigned char *orange = stbi_load("orange.jpg", &width2, &height2, &channels2, 0);
for(i=0;i<width1;i++){
new_width = (width1[i]+width2[i])/2;
//printf("new width %d\n", new_width);
}
for(j=0;j<height1;j++){
new_height = (height1[i]+height2[i])/2;
}
stbi_write_jpg("blend1.jpg", new_width, new_height, channels1, apple, 100);
stbi_image_free(apple);
printf("Blend image with a width of %dpx, a height of %dpx and %d channels\n", new_width, new_height, channels1);
}
However, I got error:
15:01:56 **** Incremental Build of configuration Debug for project Avg_blend ****
Info: Internal Builder is used for build
gcc -O0 -g3 -Wall -c -fmessage-length=0 -o Blend.o "..\\Blend.c"
..\Blend.c: In function 'main':
..\Blend.c:16:26: error: subscripted value is neither array nor pointer nor vector
new_width = (width1[i]+width2[i])/2;
^
..\Blend.c:16:36: error: subscripted value is neither array nor pointer nor vector
new_width = (width1[i]+width2[i])/2;
^
..\Blend.c:20:28: error: subscripted value is neither array nor pointer nor vector
new_height = (height1[i]+height2[i])/2;
^
..\Blend.c:20:39: error: subscripted value is neither array nor pointer nor vector
new_height = (height1[i]+height2[i])/2;
^
..\Blend.c:13:21: warning: unused variable 'orange' [-Wunused-variable]
unsigned char *orange = stbi_load("orange.jpg", &width2, &height2, &channels2, 0);
^~~~~~
15:01:57 Build Failed. 4 errors, 1 warnings. (took 303ms)
What is the wrong with my code?
Thank you.