Question: write a program to output an image that contains only 3 quadrants, upper right, upper left and bottom left. The original image is 256x256 pixels

write a program to output an image that contains only 3 quadrants, upper right, upper left and bottom left. The original image is 256x256 pixels called mri.pgm. Using C and preferrably for loop. It is a 256x256 pixels.

1.Edit or add the code below to get only 3 quadrants.

2. Write a program to keep the even while discarding the odd pixels. The original image is 256x256 pixels. We want it to be 128x128 pixelswrite a program to output an image that contains only 3 quadrants,

#include

#include

int main(int argc, char *argv[]){

unsigned sizeX; //image width

unsigned sizeY; //image height

unsigned char *image; //image array

unsigned levels;

//read image from file

FILE *iFile = fopen("mri.pgm","r");

if(iFile==0) return 1;

if(3!=fscanf(iFile, "P5 %d %d %d ", &sizeX, &sizeY, &levels)) return 1;

image=(unsigned char *) malloc(sizeX*sizeY);

fread(image,sizeof(unsigned char),sizeX*sizeY,iFile);

fclose(iFile);

//write image to file

iFile = fopen("mri2.pgm","w");

if(iFile==0) return 1; //error handling

fprintf(iFile, "P5 %d %d %d ",sizeX,sizeY, 255);//write header

fwrite(image,sizeof(unsigned char),sizeX*sizeY,iFile);//write binary image

fclose(iFile);

return 0;

}

E 100% @ mri.pgm Properties Size 256 256 pixels Type PGM image File Size 65.6 KB Folder Desktop Aperture Exposure Focal Length ISO Metering Camera Date Time E 100% @ mri.pgm Properties Size 256 256 pixels Type PGM image File Size 65.6 KB Folder Desktop Aperture Exposure Focal Length ISO Metering Camera Date Time

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!