/* * Main */ int main(int argc, char *argv[]) { int i, j; int sobel_y[3][3] = {{-1, -2, -1}, {0, 0, 0}, {1, 2, 1}}; int sobel_x[3][3] = {{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}}; Image src; Image G_y; Image G_x; Image out; if (argc < 2) { fprintf(stderr, "Pass the name of a PGM P5 file.\n"); return 1; } // Read source PGM file if (read_PGM(argv[1], &src)) return 1; // Initialize all the matrices to be of the same size as the source image. init_matrix(src, &G_y); init_matrix(src, &G_x); init_matrix(src, &out); // Convolve the Sobel filters with the source image convolve(sobel_y, src, &G_y); convolve(sobel_x, src, &G_x); // Calculate the gradient magnitude and put it in out. sobel_grad_mag(&out, G_y, G_x); // Normalize values to 0-255 normalize(&G_y); normalize(&G_x); normalize(&out); // Write final output PGMs if (write_PGM("g_y.pgm", G_y)) return 1; if (write_PGM("g_x.pgm", G_x)) return 1; if (write_PGM("out.pgm", out)) return 1; // Free the matrices dealloc_matrix(src.img, src.row); dealloc_matrix(G_y.img, 4); dealloc_matrix(G_x.img, 4); dealloc_matrix(out.img, out.row); return 0; }
int main(int argc, char *argv[]) { int n = 3; //rows int m = 3; //cols double **matrix; FILE *fp; //Det could be computed only from square matrix if (n != m && n > 1) error(2); fp = fopen("matrix.txt", "r"); if (!fp) error(0); matrix = alloc_matrix(n, m); parse_file(fp, matrix, n, m); print_matrix(matrix, n, m); printf("Det: %f\n", compute_det(matrix, n)); dealloc_matrix(matrix, n); fclose(fp); getchar(); return 0; }