Read a PGM image, store it in an array, and output it to a new file (with a different name!). Once you get that working, see if you can get any of the following working: Create a photographic negative of it (if a pixel with value 32 is dark gray, and a pixel with a value of maxval (usually 255) is white, what gray level is a pixel of maxval - 32 ?) Create a thumbnail (max # rows or columns: 64) Rotate it 180 degrees (simple...read the data and store it in the array starting at the end instead of the beginning) And here\'s a cool one: subtract each pixel from the one right above it. (For row 0, set it to zero.) Then add 1/2 maxval, so none of your output pixels are negative, and \'no difference\' is mid-level gray. Do it, look at it, and figure out why it looks the way it does. BTW, this is essentially doing a horizontal high-pass filter of the image. What features are left, and what features disappear? because we\'re not doing dynamic memory allocation yet, you\'ll need to declare an array large enough to hold \"any\" image. Assume a max size of 300 x 300 pixels, and simply output an error message if the user gives you an image larger than that. Then keep track of how much of the array you\'ve actually used. For some of these tasks, it\'s easiest to have 2 arrays, one for reading into, and one to put the result in. You can do this with a 1-dimensional array; just keep reading pixels one after another in a loop from 1 to ncols * nrows. VERY IMPORTANT: For very obscure reasons, in Visual Studio, you may need to put the following at the top of your program. You\'ll know you need it if your program crashes when it reaches the statement which declares your array(s): (Why? This increases the slack size to 16 MB. Default stack size on MS C+ + is I MB, and an integer array of 512 times 512 will overflow the stack. I told you it was obscure... BTW, dynamic memory allocation and pointers is the right way to do this, but we\'re not there yet. It can also be done using C++ vectors, which, again, we\'ll get to later) First one to send me a program that accomplishes any of the bullets above wins. (But you should do the required part of the lab first.)
Since , the language to be used is not mentioned whcih is java, c++ or matlab , I\'m currently trying to write the code in java
//convert image into photographic negative of it :
public class ngeative {
BufferedImage img=null;
File f =null;
//read image
try {
f= new File (\"D:\\\\Image\\\\test.PMG\");
img=ImageIo.read(f);
} catch(IOException e) {
System.out.println(e);
}
//get image width and height
int width=img.getWidth();
int height=img.getHeight();
//convert into negative
for(int y=0,y<height,y++)
{
for (intx=0;x<width,x++)
{
int p=img.getRGB(x,y);
int a =(p>>24)&0xff;
int r=(p>>16)&oxff;
int g=(p>>8)&0xff;
int b=&0xff;
//subtract RGB from 255
r=255-r;
g=255-g;
b=255-b;
//get new RGB value
p=(a<<24)| (r<<16)|(g<<8)|b;
image.setRGB(x,y,p);
}
}
//write image
try{
f=new File(\"D:\\\\image\\\\test.PMG\");
ImageIo.write(img,\"PMG\", f);
}Catch (IOExecption e) {
System.out.println(e);
}
}
}