reset password
Author Message
kknaur
Posts: 540
Posted 07:40 Feb 28, 2015 |

Hey All,

Because of the way C++ stores char values (as signed types instead of unsigned), we need to do some casting in order for the image coloring functions to work.  Leave the internal array as a regular char type (it has to be because the read and write methods of the file stream objects only accept arrays of char type) but use an unsigned type before the calculation.

When you are performing the calculations to change the coloring of the array,  take the RGB values from the array and assign them to an unsigned char type BEFORE doing the calculation.  See the example below.

unsigned char oldRed = image_arr[0];
unsigned char oldGreen = image_arr[1];
unsigned char oldBlue = image_arr[2];

Now use these values (oldRed, oldGreen, oldBlue) in the formulas given for the color conversions.

If your images are coming out to like the bad versions it is because you did not use an unsigned char for the calculation:

                  Bad Grayscale:                                                                   Good Grayscale:

                                           

 

                      Bad Sepia                                                                        Good Sepia

                          

I will also mention this in class on Tuesday / Wednesday but this should help for over the weekend.

Last edited by kknaur at 07:58 Feb 28, 2015.
kknaur
Posts: 540
Posted 16:52 Feb 28, 2015 |

Another thing I forgot to mention.  When you are reading the data for the images, you need to ignore the new line character that is after the maxval value and before the pixel data.  If you do not ignore this character, then when you use the read() function it will become the first character of the array, throwing everything off.

ggonza83
Posts: 14
Posted 16:39 Mar 07, 2015 |

I have been researching how to ignore the newline feed ACSii character, but with no luck. Can you provide a resource that will guide us on how to properly ignore that one character? I have tried cin.ignore() and cin.clear(), and still no luck.

kknaur
Posts: 540
Posted 17:10 Mar 07, 2015 |
ggonza83 wrote:

I have been researching how to ignore the newline feed ACSii character, but with no luck. Can you provide a resource that will guide us on how to properly ignore that one character? I have tried cin.ignore() and cin.clear(), and still no luck.

Well you already mentioned an option not working, and one of those options is the way to accomplish what you ask.  You should read the nonpixel data of the image using normal I/O and then the pixel data using the read() function.  See the example on binary I/O posted with the homework description as well as the lecture on strings.  You already have all the information you need to make this work.

ggonza83
Posts: 14
Posted 17:52 Mar 07, 2015 |

I rectified the issue. Thank you for the help Keenan.

se1k1h1mawar1
Posts: 121
Posted 17:10 Mar 09, 2015 |

To: Keenan or somebody who has the correct Nagative scale output,

Is there any way you would post Good Negativescale image so that we can compare our work against it?

Thank you,