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;
}









share|improve this question









New contributor




Sohaib F is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 2




    What is the line *detect_edges(arguments_t *args); in main 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 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

















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;
}









share|improve this question









New contributor




Sohaib F is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 2




    What is the line *detect_edges(arguments_t *args); in main 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 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















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;
}









share|improve this question









New contributor




Sohaib F is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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






share|improve this question









New contributor




Sohaib F is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Sohaib F is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 9 hours ago









Kevin Workman

32.9k53967




32.9k53967






New contributor




Sohaib F is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 10 hours ago









Sohaib F

1




1




New contributor




Sohaib F is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Sohaib F is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Sohaib F is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 2




    What is the line *detect_edges(arguments_t *args); in main 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 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
















  • 2




    What is the line *detect_edges(arguments_t *args); in main 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 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










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



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Sohaib F is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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






























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.










 

draft saved


draft discarded


















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.















 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Trompette piccolo

Slow SSRS Report in dynamic grouping and multiple parameters

Simon Yates (cyclisme)