Image processing, edge detection with pthreads
up vote
-1
down vote
favorite
I am trying to add pthreads to an image processing code that detects image edges. My compiler is giving me an error when I try to compile using:
gcc -o output imageProcessing_thread.c -lglut -lGL -lm -pthread
The error that I am getting is:
imageProcessing_thread.c: In function ‘main’:
imageProcessing_thread.c:145:17: error: expected expression before ‘arguments_t’ *detect_edges(arguments_t *args);
I have no clue what things I may be doing wrong. Any and all advice/suggestions would be really appreciated. I would love it if you advised me on how to implement the pthreads better as well.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <malloc.h>
#include <signal.h>
#include <pthread.h>
#define width 100
#define height 72
#define n_threads 4
typedef struct arguments_t {
int start;
int stride;
} arguments_t;
void process(int x) {
int i;
pthread_t *t = malloc(sizeof(pthread_t) * n_threads);
arguments_t *a = malloc(sizeof(arguments_t) * n_threads);
for (i = 0; i < n_threads; i++) {
if (i == 0) {
a[i].start = 0;
a[i].stride = 64;
} else if (64 < i < 129) {
a[i].start = 65;
a[i].stride = 128;
} else if (128 < i < 193) {
a[i].start = 129;
a[i].stride = 192;
} else if (192 < i < 256) {
a[i].start = 193;
a[i].stride = 255;
}
}
}
void *process_image() {
int i;
for (i = 0; i < n_threads; i++) {
pthread_create(&t[i], NULL, process_image, &a[i]);
}
for (i = 0; i < n_threads; i++) {
pthread_join(t[i], NULL);
}
free(t);
free(a);
}
unsigned char image, results[width * height];
void *detect_edges(arguments_t *args) {
unsigned char *in;
unsigned char *out;
int i;
int n_pixels = width * height;
for(i=0;i<n_pixels;i++) {
int x, y; // the pixel of interest
int b, d, f, h; // the pixels adjacent to x,y used for the calculation
int r; // the result of calculate
y = i / width;
x = i - (width * y);
if (x == 0 || y == 0 || x == width - 1 || y == height - 1) {
results[i] = 0;
} else {
b = i + width;
d = i - 1;
f = i + 1;
h = i - width;
r = (in[i] * 4) + (in[b] * -1) + (in[d] * -1) + (in[f] * -1)
+ (in[h] * -1);
if (r > 0) { // if the result is positive this is an edge pixel
out[i] = 255;
} else {
out[i] = 0;
}
}
}
}
void tidy_and_exit() {
exit(0);
}
void sigint_callback(int signal_number) {
printf("nInterrupt from keyboardn");
tidy_and_exit();
}
static void display() {
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos4i(-1, -1, 0, 1);
glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, image);
glRasterPos4i(0, -1, 0, 1);
glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, results);
glFlush();
}
static void key_pressed(unsigned char key, int x, int y) {
switch(key){
case 27: // escape
tidy_and_exit();
break;
default:
printf("nPress escape to exitn");
break;
}
}
int main(int argc, char **argv) {
signal(SIGINT, sigint_callback);
printf("image dimensions %dx%dn", width, height);
*detect_edges(arguments_t *args);
glutInit(&argc, argv);
glutInitWindowSize(width * 2,height);
glutInitDisplayMode(GLUT_SINGLE | GLUT_LUMINANCE);
glutCreateWindow("6CS005 Image Progessing Courework");
glutDisplayFunc(display);
glutKeyboardFunc(key_pressed);
glClearColor(0.0, 1.0, 0.0, 1.0);
glutMainLoop();
tidy_and_exit();
return 0;
}
c multithreading image pthreads
New contributor
add a comment |
up vote
-1
down vote
favorite
I am trying to add pthreads to an image processing code that detects image edges. My compiler is giving me an error when I try to compile using:
gcc -o output imageProcessing_thread.c -lglut -lGL -lm -pthread
The error that I am getting is:
imageProcessing_thread.c: In function ‘main’:
imageProcessing_thread.c:145:17: error: expected expression before ‘arguments_t’ *detect_edges(arguments_t *args);
I have no clue what things I may be doing wrong. Any and all advice/suggestions would be really appreciated. I would love it if you advised me on how to implement the pthreads better as well.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <malloc.h>
#include <signal.h>
#include <pthread.h>
#define width 100
#define height 72
#define n_threads 4
typedef struct arguments_t {
int start;
int stride;
} arguments_t;
void process(int x) {
int i;
pthread_t *t = malloc(sizeof(pthread_t) * n_threads);
arguments_t *a = malloc(sizeof(arguments_t) * n_threads);
for (i = 0; i < n_threads; i++) {
if (i == 0) {
a[i].start = 0;
a[i].stride = 64;
} else if (64 < i < 129) {
a[i].start = 65;
a[i].stride = 128;
} else if (128 < i < 193) {
a[i].start = 129;
a[i].stride = 192;
} else if (192 < i < 256) {
a[i].start = 193;
a[i].stride = 255;
}
}
}
void *process_image() {
int i;
for (i = 0; i < n_threads; i++) {
pthread_create(&t[i], NULL, process_image, &a[i]);
}
for (i = 0; i < n_threads; i++) {
pthread_join(t[i], NULL);
}
free(t);
free(a);
}
unsigned char image, results[width * height];
void *detect_edges(arguments_t *args) {
unsigned char *in;
unsigned char *out;
int i;
int n_pixels = width * height;
for(i=0;i<n_pixels;i++) {
int x, y; // the pixel of interest
int b, d, f, h; // the pixels adjacent to x,y used for the calculation
int r; // the result of calculate
y = i / width;
x = i - (width * y);
if (x == 0 || y == 0 || x == width - 1 || y == height - 1) {
results[i] = 0;
} else {
b = i + width;
d = i - 1;
f = i + 1;
h = i - width;
r = (in[i] * 4) + (in[b] * -1) + (in[d] * -1) + (in[f] * -1)
+ (in[h] * -1);
if (r > 0) { // if the result is positive this is an edge pixel
out[i] = 255;
} else {
out[i] = 0;
}
}
}
}
void tidy_and_exit() {
exit(0);
}
void sigint_callback(int signal_number) {
printf("nInterrupt from keyboardn");
tidy_and_exit();
}
static void display() {
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos4i(-1, -1, 0, 1);
glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, image);
glRasterPos4i(0, -1, 0, 1);
glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, results);
glFlush();
}
static void key_pressed(unsigned char key, int x, int y) {
switch(key){
case 27: // escape
tidy_and_exit();
break;
default:
printf("nPress escape to exitn");
break;
}
}
int main(int argc, char **argv) {
signal(SIGINT, sigint_callback);
printf("image dimensions %dx%dn", width, height);
*detect_edges(arguments_t *args);
glutInit(&argc, argv);
glutInitWindowSize(width * 2,height);
glutInitDisplayMode(GLUT_SINGLE | GLUT_LUMINANCE);
glutCreateWindow("6CS005 Image Progessing Courework");
glutDisplayFunc(display);
glutKeyboardFunc(key_pressed);
glClearColor(0.0, 1.0, 0.0, 1.0);
glutMainLoop();
tidy_and_exit();
return 0;
}
c multithreading image pthreads
New contributor
2
What is the line*detect_edges(arguments_t *args);
inmain
expected to do?
– Chris Turner
10 hours ago
1
Looks like a case of the completely unhelpful compiler error message. It only gets worse when you switch to C++, and a single mistake gives you a whole cascade of unhelpful error messages. First step is to look closely at the line in question to see whether it really says what you meant for it to say. For example, why did you put a*
in front of what looks like a call todetect_edges(...)
? And, you seem to be using a variable,args
, in that call, but where is the variable declared? Where was it assigned?
– Solomon Slow
10 hours ago
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I am trying to add pthreads to an image processing code that detects image edges. My compiler is giving me an error when I try to compile using:
gcc -o output imageProcessing_thread.c -lglut -lGL -lm -pthread
The error that I am getting is:
imageProcessing_thread.c: In function ‘main’:
imageProcessing_thread.c:145:17: error: expected expression before ‘arguments_t’ *detect_edges(arguments_t *args);
I have no clue what things I may be doing wrong. Any and all advice/suggestions would be really appreciated. I would love it if you advised me on how to implement the pthreads better as well.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <malloc.h>
#include <signal.h>
#include <pthread.h>
#define width 100
#define height 72
#define n_threads 4
typedef struct arguments_t {
int start;
int stride;
} arguments_t;
void process(int x) {
int i;
pthread_t *t = malloc(sizeof(pthread_t) * n_threads);
arguments_t *a = malloc(sizeof(arguments_t) * n_threads);
for (i = 0; i < n_threads; i++) {
if (i == 0) {
a[i].start = 0;
a[i].stride = 64;
} else if (64 < i < 129) {
a[i].start = 65;
a[i].stride = 128;
} else if (128 < i < 193) {
a[i].start = 129;
a[i].stride = 192;
} else if (192 < i < 256) {
a[i].start = 193;
a[i].stride = 255;
}
}
}
void *process_image() {
int i;
for (i = 0; i < n_threads; i++) {
pthread_create(&t[i], NULL, process_image, &a[i]);
}
for (i = 0; i < n_threads; i++) {
pthread_join(t[i], NULL);
}
free(t);
free(a);
}
unsigned char image, results[width * height];
void *detect_edges(arguments_t *args) {
unsigned char *in;
unsigned char *out;
int i;
int n_pixels = width * height;
for(i=0;i<n_pixels;i++) {
int x, y; // the pixel of interest
int b, d, f, h; // the pixels adjacent to x,y used for the calculation
int r; // the result of calculate
y = i / width;
x = i - (width * y);
if (x == 0 || y == 0 || x == width - 1 || y == height - 1) {
results[i] = 0;
} else {
b = i + width;
d = i - 1;
f = i + 1;
h = i - width;
r = (in[i] * 4) + (in[b] * -1) + (in[d] * -1) + (in[f] * -1)
+ (in[h] * -1);
if (r > 0) { // if the result is positive this is an edge pixel
out[i] = 255;
} else {
out[i] = 0;
}
}
}
}
void tidy_and_exit() {
exit(0);
}
void sigint_callback(int signal_number) {
printf("nInterrupt from keyboardn");
tidy_and_exit();
}
static void display() {
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos4i(-1, -1, 0, 1);
glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, image);
glRasterPos4i(0, -1, 0, 1);
glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, results);
glFlush();
}
static void key_pressed(unsigned char key, int x, int y) {
switch(key){
case 27: // escape
tidy_and_exit();
break;
default:
printf("nPress escape to exitn");
break;
}
}
int main(int argc, char **argv) {
signal(SIGINT, sigint_callback);
printf("image dimensions %dx%dn", width, height);
*detect_edges(arguments_t *args);
glutInit(&argc, argv);
glutInitWindowSize(width * 2,height);
glutInitDisplayMode(GLUT_SINGLE | GLUT_LUMINANCE);
glutCreateWindow("6CS005 Image Progessing Courework");
glutDisplayFunc(display);
glutKeyboardFunc(key_pressed);
glClearColor(0.0, 1.0, 0.0, 1.0);
glutMainLoop();
tidy_and_exit();
return 0;
}
c multithreading image pthreads
New contributor
I am trying to add pthreads to an image processing code that detects image edges. My compiler is giving me an error when I try to compile using:
gcc -o output imageProcessing_thread.c -lglut -lGL -lm -pthread
The error that I am getting is:
imageProcessing_thread.c: In function ‘main’:
imageProcessing_thread.c:145:17: error: expected expression before ‘arguments_t’ *detect_edges(arguments_t *args);
I have no clue what things I may be doing wrong. Any and all advice/suggestions would be really appreciated. I would love it if you advised me on how to implement the pthreads better as well.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <malloc.h>
#include <signal.h>
#include <pthread.h>
#define width 100
#define height 72
#define n_threads 4
typedef struct arguments_t {
int start;
int stride;
} arguments_t;
void process(int x) {
int i;
pthread_t *t = malloc(sizeof(pthread_t) * n_threads);
arguments_t *a = malloc(sizeof(arguments_t) * n_threads);
for (i = 0; i < n_threads; i++) {
if (i == 0) {
a[i].start = 0;
a[i].stride = 64;
} else if (64 < i < 129) {
a[i].start = 65;
a[i].stride = 128;
} else if (128 < i < 193) {
a[i].start = 129;
a[i].stride = 192;
} else if (192 < i < 256) {
a[i].start = 193;
a[i].stride = 255;
}
}
}
void *process_image() {
int i;
for (i = 0; i < n_threads; i++) {
pthread_create(&t[i], NULL, process_image, &a[i]);
}
for (i = 0; i < n_threads; i++) {
pthread_join(t[i], NULL);
}
free(t);
free(a);
}
unsigned char image, results[width * height];
void *detect_edges(arguments_t *args) {
unsigned char *in;
unsigned char *out;
int i;
int n_pixels = width * height;
for(i=0;i<n_pixels;i++) {
int x, y; // the pixel of interest
int b, d, f, h; // the pixels adjacent to x,y used for the calculation
int r; // the result of calculate
y = i / width;
x = i - (width * y);
if (x == 0 || y == 0 || x == width - 1 || y == height - 1) {
results[i] = 0;
} else {
b = i + width;
d = i - 1;
f = i + 1;
h = i - width;
r = (in[i] * 4) + (in[b] * -1) + (in[d] * -1) + (in[f] * -1)
+ (in[h] * -1);
if (r > 0) { // if the result is positive this is an edge pixel
out[i] = 255;
} else {
out[i] = 0;
}
}
}
}
void tidy_and_exit() {
exit(0);
}
void sigint_callback(int signal_number) {
printf("nInterrupt from keyboardn");
tidy_and_exit();
}
static void display() {
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos4i(-1, -1, 0, 1);
glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, image);
glRasterPos4i(0, -1, 0, 1);
glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, results);
glFlush();
}
static void key_pressed(unsigned char key, int x, int y) {
switch(key){
case 27: // escape
tidy_and_exit();
break;
default:
printf("nPress escape to exitn");
break;
}
}
int main(int argc, char **argv) {
signal(SIGINT, sigint_callback);
printf("image dimensions %dx%dn", width, height);
*detect_edges(arguments_t *args);
glutInit(&argc, argv);
glutInitWindowSize(width * 2,height);
glutInitDisplayMode(GLUT_SINGLE | GLUT_LUMINANCE);
glutCreateWindow("6CS005 Image Progessing Courework");
glutDisplayFunc(display);
glutKeyboardFunc(key_pressed);
glClearColor(0.0, 1.0, 0.0, 1.0);
glutMainLoop();
tidy_and_exit();
return 0;
}
c multithreading image pthreads
c multithreading image pthreads
New contributor
New contributor
edited 9 hours ago
Kevin Workman
32.9k53967
32.9k53967
New contributor
asked 10 hours ago
Sohaib F
1
1
New contributor
New contributor
2
What is the line*detect_edges(arguments_t *args);
inmain
expected to do?
– Chris Turner
10 hours ago
1
Looks like a case of the completely unhelpful compiler error message. It only gets worse when you switch to C++, and a single mistake gives you a whole cascade of unhelpful error messages. First step is to look closely at the line in question to see whether it really says what you meant for it to say. For example, why did you put a*
in front of what looks like a call todetect_edges(...)
? And, you seem to be using a variable,args
, in that call, but where is the variable declared? Where was it assigned?
– Solomon Slow
10 hours ago
add a comment |
2
What is the line*detect_edges(arguments_t *args);
inmain
expected to do?
– Chris Turner
10 hours ago
1
Looks like a case of the completely unhelpful compiler error message. It only gets worse when you switch to C++, and a single mistake gives you a whole cascade of unhelpful error messages. First step is to look closely at the line in question to see whether it really says what you meant for it to say. For example, why did you put a*
in front of what looks like a call todetect_edges(...)
? And, you seem to be using a variable,args
, in that call, but where is the variable declared? Where was it assigned?
– Solomon Slow
10 hours ago
2
2
What is the line
*detect_edges(arguments_t *args);
in main
expected to do?– Chris Turner
10 hours ago
What is the line
*detect_edges(arguments_t *args);
in main
expected to do?– Chris Turner
10 hours ago
1
1
Looks like a case of the completely unhelpful compiler error message. It only gets worse when you switch to C++, and a single mistake gives you a whole cascade of unhelpful error messages. First step is to look closely at the line in question to see whether it really says what you meant for it to say. For example, why did you put a
*
in front of what looks like a call to detect_edges(...)
? And, you seem to be using a variable, args
, in that call, but where is the variable declared? Where was it assigned?– Solomon Slow
10 hours ago
Looks like a case of the completely unhelpful compiler error message. It only gets worse when you switch to C++, and a single mistake gives you a whole cascade of unhelpful error messages. First step is to look closely at the line in question to see whether it really says what you meant for it to say. For example, why did you put a
*
in front of what looks like a call to detect_edges(...)
? And, you seem to be using a variable, args
, in that call, but where is the variable declared? Where was it assigned?– Solomon Slow
10 hours ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sohaib F is a new contributor. Be nice, and check out our Code of Conduct.
Sohaib F is a new contributor. Be nice, and check out our Code of Conduct.
Sohaib F is a new contributor. Be nice, and check out our Code of Conduct.
Sohaib F is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416151%2fimage-processing-edge-detection-with-pthreads%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
What is the line
*detect_edges(arguments_t *args);
inmain
expected to do?– Chris Turner
10 hours ago
1
Looks like a case of the completely unhelpful compiler error message. It only gets worse when you switch to C++, and a single mistake gives you a whole cascade of unhelpful error messages. First step is to look closely at the line in question to see whether it really says what you meant for it to say. For example, why did you put a
*
in front of what looks like a call todetect_edges(...)
? And, you seem to be using a variable,args
, in that call, but where is the variable declared? Where was it assigned?– Solomon Slow
10 hours ago