Thread: negative of an image

  1. #1
    Registered User
    Join Date
    Feb 2019
    Posts
    2

    Post negative of an image

    Write a C program to compute the photographic negative of an image. The program should be able to read the input image from an ASCII file, visit each pixel, and compute its photographic negative value (explained below). The program should save the output into an ASCII file of exactly the same format as the input file. Call the output file testimageneg.dat.

    To produce the photographic negative of an image, the value of each pixel is replaced by the sum of its negative plus the upper end of the grayscale. For example, for an 8-bit system, the lower end of the grayscale could be 1, in which case the upper end would be 256. A pixel value of 10 (almost black) in the original image gets replaced with 256-10 = 246.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So what's the problem?

    You could try just reading the image in and just printing pixel values.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    Note that 8-bit values actually range from 0 to 255, so you need to subtract a value from 255 (not 256) to get the "photographic negative" value.

    (Oftentimes images are gamma corrected, which means the "proper" method requires you to reverse the gamma correction, negate the values, and re-apply gamma correction. But simply negating the gamma-corrected values works well enough for a simple programming exercise.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-04-2016, 08:11 AM
  2. Replies: 1
    Last Post: 03-16-2015, 06:28 AM
  3. Replies: 4
    Last Post: 03-13-2010, 05:10 AM
  4. Replies: 13
    Last Post: 11-20-2009, 04:43 PM
  5. Problems with Image Magick [Unable to Quantisize Image]
    By Maragato in forum C Programming
    Replies: 1
    Last Post: 09-18-2006, 10:41 PM

Tags for this Thread