image_filtering.c
int apply_filter_gray(image *img_in, gray_pixel **img_block, int rank, int block_size, int length, char *filter_name)
{
	for (int filter_idx = 0; filter_idx < 5; filter_idx++)
	{
		if (strcmp(filter_name, filter_names[filter_idx]) == 0)
		{
			float new_gray_pixel;
			int lin, col;
			for (int i = 0; i < length; i++)
			{
				lin = (block_size * rank + i) / (img_in->width);
				col = (block_size * rank + i) % (img_in->width);
				if ((lin > 0) && (lin < (img_in->height - 1)) && (col > 0) && (col < (img_in->width - 1)))
				{
					new_gray_pixel = 0;
					for (int i_f = -1; i_f < 2; i_f++)
						for (int j_f = -1; j_f < 2; j_f++)
							new_gray_pixel += filters[filter_idx][i_f + 1][j_f + 1] * (float)(img_in->gray_image)[(lin + i_f) * (img_in->width) + (col + j_f)];
					(*img_block)[i] = (gray_pixel)new_gray_pixel;
				}
				else
					(*img_block)[i] = (img_in->gray_image)[lin * (img_in->width) + col];
			}
			return STATUS_SUCCES;
		}
		else if (filter_idx == 4)
		{
			printf("Filter \"%s\" is an invalid filter name. Available filters: smooth, blur, sharpen, mean, emboss.\n", filter_name);
			return ERR_INVALID_FILTER_NAME;
		}
	}
	return STATUS_SUCCES;
}
// Apply a filter whose name is from the filter_name list on a grayscale image
Apply a filter whose name is from the filter_name list on a grayscale image
Apply a filter whose name is from the filter_name list on a grayscale image
int apply_filter_gray(image *img_in, gray_pixel **img_block, int rank, int block_size, int length, char *filter_name)
{
	for (int filter_idx = 0; filter_idx < 5; filter_idx++)
	{
		if (strcmp(filter_name, filter_names[filter_idx]) == 0)
		{
			float new_gray_pixel;
			int lin, col;
			for (int i = 0; i < length; i++)
			{
				lin = (block_size * rank + i) / (img_in->width);
				col = (block_size * rank + i) % (img_in->width);
				if ((lin > 0) && (lin < (img_in->height - 1)) && (col > 0) && (col < (img_in->width - 1)))
				{
					new_gray_pixel = 0;
					for (int i_f = -1; i_f < 2; i_f++)
						for (int j_f = -1; j_f < 2; j_f++)
							new_gray_pixel += filters[filter_idx][i_f + 1][j_f + 1] * (float)(img_in->gray_image)[(lin + i_f) * (img_in->width) + (col + j_f)];
					(*img_block)[i] = (gray_pixel)new_gray_pixel;
				}
				else
					(*img_block)[i] = (img_in->gray_image)[lin * (img_in->width) + col];
			}
			return STATUS_SUCCES;
		}
		else if (filter_idx == 4)
		{
			printf("Filter \"%s\" is an invalid filter name. Available filters: smooth, blur, sharpen, mean, emboss.\n", filter_name);
			return ERR_INVALID_FILTER_NAME;
		}
	}
	return STATUS_SUCCES;
}
int apply_filter_gray ( image * img_in , gray_pixel * * img_block , int rank , int block_size , int length , char * filter_name ) { for ( int filter_idx = 0 ; filter_idx < 5 ; filter_idx ++ ) { if ( strcmp ( filter_name , filter_names [ filter_idx ] ) == 0 ) { float new_gray_pixel ; int lin , col ; for ( int i = 0 ; i < length ; i ++ ) { lin = ( block_size * rank + i ) / ( img_in -> width ) ; col = ( block_size * rank + i ) % ( img_in -> width ) ; if ( ( lin > 0 ) && ( lin < ( img_in -> height - 1 ) ) && ( col > 0 ) && ( col < ( img_in -> width - 1 ) ) ) { new_gray_pixel = 0 ; for ( int i_f = -1 ; i_f < 2 ; i_f ++ ) for ( int j_f = -1 ; j_f < 2 ; j_f ++ ) new_gray_pixel += filters [ filter_idx ] [ i_f + 1 ] [ j_f + 1 ] * ( float ) ( img_in -> gray_image ) [ ( lin + i_f ) * ( img_in -> width ) + ( col + j_f ) ] ; ( * img_block ) [ i ] = ( gray_pixel ) new_gray_pixel ; } else ( * img_block ) [ i ] = ( img_in -> gray_image ) [ lin * ( img_in -> width ) + col ] ; } return STATUS_SUCCES ; } else if ( filter_idx == 4 ) { printf ( " \" \" \n " , filter_name ) ; return ERR_INVALID_FILTER_NAME ; } } return STATUS_SUCCES ; }
Apply a filter whose name is from the filter_name list on a grayscale image
Apply a filter whose name is from the filter_name list on a grayscale image