#include <windows.h>
#include "common.h"

Image_data * Binarize(Image_data *piData, int T)
{
	int i, numpixels;
	Image_data *pproData;

// ----------- Memory allocation stuff --------------//

	pproData = malloc(sizeof(Image_data));
	pproData->image_G_ptr = malloc(piData->n_rows * piData->n_cols);
	pproData->n_cols = piData->n_cols;
	pproData->n_rows = piData->n_rows;
	lstrcpy(pproData->filename, "Binary Image");

// -------------------------------------------------//


	numpixels = piData->n_rows * piData->n_cols;

	for (i = 0; i < numpixels; i++)
	{
		if (piData->image_G_ptr[i] > T)
			pproData->image_G_ptr[i] = 255;
		else
			pproData->image_G_ptr[i] = 0;
	}

	return pproData;

}