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 pixels
#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 TimeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started