Hello I wanna make a c++ code for image thresholding.The format of the image is ppm or pgm and and I have to use only the standard library.
I wrote the read and write codes for the image but I need help for the thresholding.
Any help please?
Look at each pixel in the source image.
If pixel value is bigger than threshold_value, set same pixel in output picture to white.
If pixel value is same or less than threshold_value, set same pixel in output picture to black.
From your question, I assume you are able to read and write images.
If the image size is Hnum X Vnum, where Vnum is vertical number of pixels and Hnum horizontal number,
You can see an image as a 2D array/matrix with each element having a value, it is intensity for normal image.
Run the for loops like the way you do for 2D arrays and access intensity value at each pixel indexed by horizontal and vertical values. Compare this value to the specified threshold and mark that pixel accordingly.
for example with in the double for loop you can use
(intensity(h,v)>threshold)?pixel(h,v)=white:pixel(h,v)=black;
Be careful in using the correct index values for horizontal and vertical directions.