Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Median of 2 images (binary file)

Reply
Thread Tools

Median of 2 images (binary file)

 
 
Nicki
Guest
Posts: n/a
 
      07-25-2010
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 )?
 
Reply With Quote
 
 
 
 
Francesco S. Carta
Guest
Posts: n/a
 
      07-25-2010
Nicki <(E-Mail Removed)>, 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
 
Reply With Quote
 
 
 
 
Nicki
Guest
Posts: n/a
 
      07-25-2010
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:os_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;
}
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      07-25-2010
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 .
 
Reply With Quote
 
Michael Doubez
Guest
Posts: n/a
 
      07-26-2010
On 25 juil, 22:54, Jorgen Grahn <(E-Mail Removed)> 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
 
Reply With Quote
 
Vladimir Jovic
Guest
Posts: n/a
 
      07-26-2010
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.
 
Reply With Quote
 
Branimir Maksimovic
Guest
Posts: n/a
 
      07-26-2010
On Mon, 26 Jul 2010 12:07:58 +0200
Vladimir Jovic <(E-Mail Removed)> 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 .

 
Reply With Quote
 
Vladimir Jovic
Guest
Posts: n/a
 
      07-26-2010
Branimir Maksimovic wrote:
> On Mon, 26 Jul 2010 12:07:58 +0200
> Vladimir Jovic <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Mean, median, and mode Josiah Carlson Python 7 12-06-2004 10:30 PM
RE: Mean, median, and mode - third time's the charm!!! Frohnhofer, James Python 0 12-06-2004 09:16 PM
RE: Mean, median, and mode Robert Brewer Python 5 12-06-2004 08:31 PM
Re: Python-Help ( Mean,Median & Mode) Alfred Canoy Python 2 12-06-2004 04:03 AM
Implementation of parallel 2D median filtering Andreas VHDL 1 12-02-2003 11:19 AM



Advertisments