Median of 2 images (binary file)

N

Nicki

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 ;))?
 
F

Francesco S. Carta

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.
 
N

Nicki

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;
}
 
J

Jorgen Grahn

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
 
M

Michael Doubez

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 ?
 
V

Vladimir Jovic

Michael said:
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.
 
V

Vladimir Jovic

Branimir said:

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top