Median of 2 images (binary file)

Discussion in 'C++' started by Nicki, Jul 25, 2010.

  1. Nicki

    Nicki Guest

    Hi everyone!

    I am completly new to programming. So far I read up a couple of things
    about c++. However I still cannot solve the following problem:
    I got 2 images (binary files) , that i have to read, find the median
    of the 2 images and then write this median image, again, as a binary
    file.

    I already figured out how to read the files, however I don't have the
    slightest idea, how to find the median of 2 binary files...
    (16bit-1032x1012 pixels).

    Can anybody help me out (maybe with source codes ;))?
     
    Nicki, Jul 25, 2010
    #1
    1. Advertising

  2. Nicki <>, on 25/07/2010 03:40:55, wrote:

    > Hi everyone!
    >
    > I am completly new to programming. So far I read up a couple of things
    > about c++. However I still cannot solve the following problem:
    > I got 2 images (binary files) , that i have to read, find the median
    > of the 2 images and then write this median image, again, as a binary
    > file.
    >
    > I already figured out how to read the files, however I don't have the
    > slightest idea, how to find the median of 2 binary files...
    > (16bit-1032x1012 pixels).
    >
    > Can anybody help me out (maybe with source codes ;))?


    What does "binary files" stand for? If it is some tagged format or it
    has other metadata, just opening the file in binary mode and mercilessly
    compute the median of all the words will corrupt the file.

    If it is a raw format that contains just data, then that would be easier.

    Follow these steps:
    - get the filenames somehow into your program
    - open the two streams for input
    - open a third one for the output
    - create a function for processing the data
    - create a loop where you extract the data from the two streams and pass
    it to the above function, then insert the return value into the output
    stream

    Try to create a program with the above directives and post it here if
    you have any problem.

    --
    FSC - http://userscripts.org/scripts/show/59948
    http://fscode.altervista.org - http://sardinias.com
     
    Francesco S. Carta, Jul 25, 2010
    #2
    1. Advertising

  3. Nicki

    Nicki Guest

    I am using greyscale pictures. So my task is to average every pixel in
    this greyscale image. First of all I don't even know how to read out
    every pixel seperately. I can only read the file as one whole thing.

    // reading a complete binary file
    #include <iostream>
    #include <fstream>
    using namespace std;

    ifstream::pos_type size;
    char * memblock;

    int main () {
    ifstream file ("example.bin", ios::in|ios::binary|ios::ate);
    if (file.is_open())
    {
    size = file.tellg();
    memblock = new char [size];
    file.seekg (0, ios::beg);
    file.read (memblock, size);
    file.close();

    cout << "the complete file content is in memory";

    delete[] memblock;
    }
    else cout << "Unable to open file";
    return 0;
    }
     
    Nicki, Jul 25, 2010
    #3
  4. Nicki

    Jorgen Grahn Guest

    On Sun, 2010-07-25, Nicki wrote:
    > I am using greyscale pictures. So my task is to average every pixel in
    > this greyscale image. First of all I don't even know how to read out
    > every pixel seperately. I can only read the file as one whole thing.


    The netpbm library comes with example code for doing such things --
    with the PPM image format. Be aware that there are hundreds of
    different bitmap image formats ... you seem to be unsure which one(s)
    you have to handle.

    (I would probably not try to reimplement this in C++, when I can just
    write a shell script combining anytopnm(), pnmarith(1) and pnmdepth(1)
    in fifteen minutes or so. Or use ImageMagick or something.)

    /Jorgen

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
     
    Jorgen Grahn, Jul 25, 2010
    #4
  5. On 25 juil, 22:54, Jorgen Grahn <> wrote:
    > On Sun, 2010-07-25, Nicki wrote:
    > > I am using greyscale pictures. So my task is to average every pixel in
    > > this greyscale image. First of all I don't even know how to read out
    > > every pixel seperately. I can only read the file as one whole thing.

    >
    > The netpbm library comes with example code for doing such things --
    > with the PPM image format. Be aware that there are hundreds of
    > different bitmap image formats ... you seem to be unsure which one(s)
    > you have to handle.


    There is also the GIL (Generic Image Library) from boost/adobe. I have
    used it and I must admit it is powerful. But I think it is a bit hard
    for a novice (unless you can find an example relevant to your
    problem).

    > (I would probably not try to reimplement this in C++, when I can just
    > write a shell script combining anytopnm(), pnmarith(1) and pnmdepth(1)
    > in fifteen minutes or so.  Or use ImageMagick or something.)


    Just out of curiosity: what is the median of two images ?

    --
    Michael
     
    Michael Doubez, Jul 26, 2010
    #5
  6. Michael Doubez wrote:
    >
    >> (I would probably not try to reimplement this in C++, when I can just
    >> write a shell script combining anytopnm(), pnmarith(1) and pnmdepth(1)
    >> in fifteen minutes or so. Or use ImageMagick or something.)

    >
    > Just out of curiosity: what is the median of two images ?


    This is a very good question :)

    If it was 3 or more, then I would understand. This way, you can take one
    of the images as the result.
     
    Vladimir Jovic, Jul 26, 2010
    #6
  7. On Mon, 26 Jul 2010 12:07:58 +0200
    Vladimir Jovic <> wrote:

    > Michael Doubez wrote:
    > >
    > >> (I would probably not try to reimplement this in C++, when I can
    > >> just write a shell script combining anytopnm(), pnmarith(1) and
    > >> pnmdepth(1) in fifteen minutes or so. Or use ImageMagick or
    > >> something.)

    > >
    > > Just out of curiosity: what is the median of two images ?

    >
    > This is a very good question :)
    >
    > If it was 3 or more, then I would understand. This way, you can take
    > one of the images as the result.


    Perhaps this:

    http://en.wikipedia.org/wiki/Median_filter

    Greets

    --
    drwxr-xr-x 2 bmaxa bmaxa 4096 2010-07-23 18:00 .
     
    Branimir Maksimovic, Jul 26, 2010
    #7
  8. Branimir Maksimovic wrote:
    > On Mon, 26 Jul 2010 12:07:58 +0200
    > Vladimir Jovic <> wrote:
    >
    >> Michael Doubez wrote:
    >>>> (I would probably not try to reimplement this in C++, when I can
    >>>> just write a shell script combining anytopnm(), pnmarith(1) and
    >>>> pnmdepth(1) in fifteen minutes or so. Or use ImageMagick or
    >>>> something.)
    >>> Just out of curiosity: what is the median of two images ?

    >> This is a very good question :)
    >>
    >> If it was 3 or more, then I would understand. This way, you can take
    >> one of the images as the result.

    >
    > Perhaps this:
    >
    > http://en.wikipedia.org/wiki/Median_filter
    >


    Yes, perhaps. But read the original post again. This is requested :

    "I am completly new to programming. So far I read up a couple of things
    about c++. However I still cannot solve the following problem:
    I got 2 images (binary files) , that i have to read, find the median
    of the 2 images and then write this median image, again, as a binary
    file."

    The requested in completely different from image filtering using 2d
    median filter, for which you do not need two images.


    I guess OP just want to average two images.
     
    Vladimir Jovic, Jul 26, 2010
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas
    Replies:
    1
    Views:
    1,662
    Tuukka Toivonen
    Dec 2, 2003
  2. Robert Brewer

    RE: Mean, median, and mode

    Robert Brewer, Dec 5, 2004, in forum: Python
    Replies:
    5
    Views:
    440
    Paul McGuire
    Dec 6, 2004
  3. Alfred Canoy

    Re: Python-Help ( Mean,Median & Mode)

    Alfred Canoy, Dec 5, 2004, in forum: Python
    Replies:
    2
    Views:
    11,179
    Dan Bishop
    Dec 6, 2004
  4. Josiah Carlson

    Re: Mean, median, and mode

    Josiah Carlson, Dec 6, 2004, in forum: Python
    Replies:
    7
    Views:
    471
    Steven Bethard
    Dec 6, 2004
  5. Replies:
    5
    Views:
    919
    Xho Jingleheimerschmidt
    Apr 2, 2009
Loading...

Share This Page