ty

tyvm
Last edited on
I'm not sure what your question is since you haven't said what you tried to do. I assume it was probably converting to grayscale since that's the function with the most trouble.

Don't typedef your structs in C++ (it's not necessary).

In readImage, you seeem to think the code you've written will read P1, P2, or P3 files, but they have different formats. Both P1 and P2 only have one integer per pixel, but you are reading three no matter what. P1 doesn't have a "max" value since the values can only be 0 or 1. Also, in your conversion to grayscale you still write out 3 (equal) ints per pixel. It should only be one value per pixel.

Your grayscale conversion is not quite right. The colors shouldn't be given equal weight. In particular our eyes are most sensitive to green. Something like this is more appropriate:

 
int gray = 0.3 * r + 0.59 * g + 0.11 * b;


Last edited on
> the new file isn't coming out correctly
¿could you be a little more descriptive?
¿is the new file being generated?, ¿the file is there but it is not an image?, ¿the result image is exactly the same as the original?, ¿the result image is all black?, ¿what?
also, ¿what are you using to check it?


> Each function is described below.
you have implemented eight functions
readImage() and writeImage() are utillities, fine
invertAll() does your "color invert" requirement. You have invert{Red,Green,Blue}() that you don't use and nobody asked
convertGrayScale() was not asked either
there is also invertGreenBlue(), ¿did you misread the asignment?

¿what of all that we should check? ¿why did you write all that without checking?
Last edited on
the new file does get generated but doesn't come out correctly.
it becomes a 1 kb file that shows "P30 -858993460 -858993460" with text and doesn't open with irfanview(gives the error of decode error, invalid or unsupported ppm file.
Last edited on
@chaddai,

File formats are rather specific, and usually binary data.

I don't know, but perhaps you know, what the format of that data is in?

What kind of image file is this?

To me, at a glance, it looks like you're expecting pixel data to be text.

That's highly unusual. Most image file formats are binary files.

What format is irfanview expecting in your situation?

Also, use code tags. They look like this:


[code]
//all source code goes here, between the tags
[/code]
Last edited on
@Niccolo, PPM has both text and binary formats. It's basically the simplest format around.
https://en.wikipedia.org/wiki/Netpbm_format

@chaddai, Did you read my post?????
I though of another potential problem. PPM files can contain comments so you should skip a line (or the rest of the line) beginning with a #.

EDIT: I was able to get it working with the stuff I said in my earlier post and also skipping comments. Perfect grayscale with the weights I gave above.
Last edited on
Topic archived. No new replies allowed.