Median Filter Algorithm with 3x3, 5x5, 7x7 pixel mask. Options to run with 1,2,3 or 4 forks - using shared memory.

Job ID: 33896096

Budget: $30 – $250 USD

I have an example algorithm that opens, handles and saves BMP files. I would need to implement a median filter in it in order to handle two BMP files. (Attached).
The focus of the work is not on the median filter algorithm, which we can even use something ready-made as long as we can call it as a function, passing the mask size as a parameter.
Ready median filter algorithm example: https://codereview.stackexchange.com/questions/262690/image-processing-median-filter-in-c

Here is my algorithm that handles BMP file:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/*------------------------------------------------ ---------------------*/
#pragma pack(1)

/*------------------------------------------------ ---------------------*/
struct header {
unsigned short type;
unsigned int file_size;
unsigned short reserved1;
unsigned short reserved2;
unsigned int offset;
unsigned int size_image_header;
int width;
int height;
unsigned short plans;
unsigned short bits_per_pixel;
unsigned int compression;
unsigned int image_size;
int resolution_width;
int resolution_height;
unsigned int number_colors;
unsigned int important_colors;
};
typedef struct header HEADER;

struct rgb {
unsigned char blue;
unsigned char green;
unsigned char red;
};
typedef struct rgb RGB;

/*------------------------------------------------ ---------------------*/
int main(int argc, char **argv ){

char input[100], output[100];
HEADER header;
RGB pixel;
int i, j;
short average;
char aux;

printf("Enter the name of the input file:\n");
scanf("%s", input);

printf("Enter the name of the output file:\n");
scanf("%s", output);


FILE *fin = fopen(input, "rb");

if ( fin == NULL ){
printf("Error opening file %s\n", input);
exit(0);
}

FILE *fout = fopen(output, "wb");

if ( fout == NULL ){
printf("Error opening file %s\n", output);
exit(0);
}

fread(&header, sizeof(HEADER), 1, fin);

printf("Image size: %u\n", header.file_size);
printf("Width: %d\n", header.width);
printf("Width: %d\n", header.height);
printf("Bits per pixel: %d\n", header.bits_per_pixel);

fwrite(&header, sizeof(HEADER), 1, fout);

RGB **mat = (RGB**)malloc(header.height*sizeof(RGB *));
for(i=0; i<header.height; i++){
mat[i] = (RGB *)malloc(header.width*sizeof(RGB));
}

for(i=0; i<header.height; i++){

int there = (header.width * 3) % 4;

if (there != 0){
there = 4 - there;
}

for(j=0; j<header.width; j++){
fread(&mat[i][j], sizeof(RGB), 1, fin);
}

for(j=0; j<there; j++){
fread(&aux, sizeof(unsigned char), 1, fin);
}
}


for(i=0; i<header.height; i++){

int there = (header.width * 3) % 4;

if (there != 0){
there = 4 - there;
}

for(j=0; j<header.width; j++){
fwrite(&mat[i][j], sizeof(RGB), 1, fout);
}

for(j=0; j<there; j++){
fwrite(&aux, sizeof(unsigned char), 1, fout);
}
}

fclose(fin);
fclose(fout);
}

What I need is someone who implements FORKS in C (for running in linux environment), with shared memory between processes - so that the user when running has a menu:

- Run median filter with 1 fork 3x3 mask
- Run median filter with 1 fork 5x5 mask
- Run median filter with 1 fork 7x7 mask
- Run median filter with 2 3x3 mask forks
... etc

The options will be 1,2,3 or 4 forks and 3x3, 5x5 and 7x7 as a mask.

so I understand that the median filter will be a function that will receive as a parameter the number of forks/shared memory and the size of the mask

The idea is that the user can apply a median filter on the same BMP running with different number of forks and different mask, so that he can compare the execution times between different mask sizes and forks.

This is part 1 of this project:
Implement menu, masking options and shared memory.
And for this part I have a very short deadline (another developer was doing it and dropped out with a few hours left).

Then I have part 2, which is to implement the same using the pthreads library, for this one, I have a deadline of 10 days.