gg I need help implementing the following function. I need help plz with some ex
ID: 3797221 • Letter: G
Question
gg
I need help implementing the following function. I need help plz with some explanation
// - This function takes in a square sized grayscale image and applies thresholding on each pixel.
// i.e. it should change pixel values according to this formula:
// 0xFF if x >= threshold
// 0x00 if x < threshold
// - The width and height of the image are equal to dim.
// - You are not allowed to define additional variables.
//
void imageThresholding(unsigned char* image, int dim, unsigned char threshold) {
__asm {
// YOUR CODE STARTS HERE
// YOUR CODE ENDS HERE
}
}
Explanation / Answer
I think for taking each pixel into consideration of any 2-d image, it must take atleast two variables for changing the pixel values. So, the function may be like this
void imageThresholding(unsigned char* image, int dim, unsigned char threshold) {
__asm {
// YOUR CODE STARTS HERE
for(int i = 0; i < dim; i++){
for(int j = 0; j < dim; j++){
int x = (image.getRed(j,i)+image.getGreen(j, i)+image.getBlue(j, i))/3;
if(x >= threshold){
image.setPixel(j,i,255,255,255,255); //to set white
}else if (x < threshold){
image.setPixel(j,i,255,0,0,0); //to set black
}
}
}
// YOUR CODE ENDS HERE
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.