how to open two image and substract them?

This is a discussion on how to open two image and substract them? within the C Programming forums, part of the General Programming Boards category; hi, does anyone know how to write in C programming to open two images and subtract them to get a ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    5

    how to open two image and substract them?

    hi,
    does anyone know how to write in C programming to open two images and subtract them to get a result ? please take note that the image is an grayscale image.

    thanks.
    Last edited by valy_mil; 01-10-2008 at 08:50 AM. Reason: typing error

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You need some sort of library that can read the image format you have - it may be part of your OS, or you may need some third party product [free or commercial]. Once you have something that can load the images and take byte by byte and subtract one from the other, and store the result as another image [or whatever you want to do with the result].

    Of course, you CAN write your own routines to load an image, but I wouldn't recommend it.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    5
    hi matsp,
    u mean i need to apply some sort of library to load in the image?
    i'm writing my program using Linux-Ubuntu. So izzit possible to use fopen to open an image?

    by the way.thanks for the previous reply.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by valy_mil View Post
    hi,
    does anyone know how to write in C programming to open two images and substract them to get a result ? please take note that the image is an grayscale image.

    thanks.
    We all know a bit about writing in C - check. Images are just files with a particular format so - check.

    "Substract" == subtract. Here, I need a much better explanation of what you want. Subtract the area of one from the area of the second one, subtract the light/dark value's from each other, what?

    It would be best if you could load an example showing the two input and one output image to Photobucket, and paste the url here so we can see what you mean.

    And of course, show us your work on this. We won't write your program for you.

    If this isn't a programming assignment, you might want to check with Gimp and other image manipulators. They may well have a facility to automatically do that for you.
    Last edited by Adak; 01-10-2008 at 02:48 AM.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Of course, you can use fopen() on an image file - the problem is that even the simplest of image files (such as Windows BMP's) aren't particularly easy to read straight away, and it gets even worse if the image is a TIFF, JPEG, PNG, GIF etc, as those have a more complex structure.

    Since there are libraries [e.g. libjpeg] that allow you to build an application that can just load a JPEG image and then access the data directly, why bother with writing hundreds or thousands of lines of code to read the image, only to do a simple operation on the data loaded [if I assume correctly that you just want to subtract each pixel from one image from the corresponding pixel of the other image].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    5
    hi matsp,
    i want to convert the jpeg to grayscale bmp because as i know, Jpeg is a lossy compression format.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So you need to have a library that supports JPEG images and BMP, and then you need some algorithm for converting to grayscale [unless the input JPEG is a grayscale already].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Jan 2008
    Posts
    5
    hi matsp,
    i'm able to convert jpeg to grayscale bmp image, just when i want to process the image i dont know how to load in the image in my C code to process the image. Can u give some guide to me on this?thanks

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,335
    Just google for "bmp file format". There's plenty of info out there.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    dra
    dra is offline
    Weak. dra's Avatar
    Join Date
    Apr 2005
    Posts
    166
    there's OpenCV, an open source computer vision and imaging library. Although if you look at my thread, I'm having some trouble getting it started in Dev-Cpp. Hope you have better luck!

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21