|
Hi,
I am not sure if I explained it right... sorry for the confusion. Like that of *.bmp images, there are *.jpg images right? My question is, how will one load this *.bmp or *.jpg picture file into an array for further processing in C/C++?? I need to say, construct a Gaussian filter or median filter or whatever, for further processing like blurring, etc... contrast, or take the FFT of the image, in this case... And then, I have to store the values obtained in a file. If it could be stored as a picture back itself, then fine, otherwise, please specify how to do it.
Its like, after calculating the fft, i run the filters from the fft obtained results, like bessel or gaussian filters and then restore the modified (blurred, in this case) image. This is what i hav to do. In case I made some mistakes in explaining here too, please specify.
thanks,
-cedance
|
|
|
|
|
So you want to load and decompress the image, and THEN do some processing on the pixels?
The CImage class can help
#include <atlimage.h>
...
CImage image;
image.Load("C:\\TEST.JPG");
Then you can use
image.GetWidth()/image.GetWidth() to get the image dimensions in pixels
image.GetBPP() to get the bits-per-pixel
image.GetPitch() to get the bytes-per-row in the pixel data
image.GetBits() to get a pointer to the RGB pixel data
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Hi Mark,
thanks a lot. Will try this one...
regards,
-cedance
|
|
|
|
|
Hi,
My understanding of your query is as follows::
You need to do some processing on the image (raw bits that means pixel values). Now you have the .jpeg image file, a compressed file. so first you need to extract the pixel values from jpeg file. As jpeg file is compressed file first you need to decompress using decompression logic.
Please refer http://www.faqs.org/faqs/jpeg-faq/part2/section-15.html[^]
Regards,
Paresh.
|
|
|
|
|
Hi paresh,
I understood finally what you mean. And thanks a lot for your link. If i have to get the pixel values from the jpeg file, then i will have to go thro the set of operations instructed by the jpeg manual to get them from the compressed jpeg file format... hope i got u right this time. Will try to do it this way too. Thanks a lot again!! this forum rocks!!
regards,
-cedance
|
|
|
|
|
You are most Welcome .
Regards,
Paresh.
|
|
|
|
|
I think I answered your query.
Regards,
Paresh.
|
|
|
|
|
Hello all,
This morning I've found something interesting: a boolean that works perfect in all the application but it fails in just one function. Just before going deeper, I know that this is impossible, so I think that I'm missing something or I'm completely stucked on that code and I cannot see why do this is happening.
Let me explain that a little bit more:
1. I have 6 instances of one class that inherits from a MSChart.
2. That class has a private boolean member "m_bGraficaTempsReal"
3. That class has a public member function that returns the value of that private boolean member.
4. That class also has a public member function that modifies the value of that private boolean member.
I've been using AfxTrace in order to know the value of that boolean along the program code (spreading it along the code itself).
Each time I click a MSChart the event that is generated is handled by the respective OnClick message handler. Then is when I call the public function that set the value of that boolean variable, in fact I'm doing this: m_bGraficaTempsReal = !m_bGraficaTempsReal; and after that I've placed one AfxTrace call in order to see if everything has gone right. Of course the value is changed only each time that I click on that graph and each time I click on it only one ONCLICK message is generated so only one time the boolean variable gets modified.
In other parts of the application I'm using the function that returns the value of that boolean variable successfully. I mean that I know the value of that variable and everything is reacting in the way it should. So in other parts of the application I know the right value of the boolean variable.
Well, I also have one OnTimer that is called each 500 milliseconds.
Inside that Ontimer I call SetValor, that is a function that modifies the value of a bar of the graph. I'm passing some parameters to that function: the number of the bar that I'm modifying, the value that I want to place there and if I want to write the little label that is in the bottom of the graph again.
Inside the SetValor function, I'm using this code:
CString buf = "";<br />
if (m_bGraficaTempsReal)<br />
{<br />
buf.Format("U%i-%.0f", iBar+1, m_vfData[iBar]);<br />
}<br />
else<br />
{<br />
buf.Format("C%i-%.0f", iBar+1, m_vfData[iBar]);<br />
}<br />
AfxTrace("\n\nBOOL VALUE: %i",m_bGraficaTempsReal);<br />
As you can see I've placed another AfxTrace in order to see which is the value of that variable at that moment.
Well this is my surprise, I'm modifying only the value of that variable in the OnClick event, and I'm clicking it only one time, and I see how the variable changes it's value.
The OnTimer is also dependant and that variable, so SetValor is not being called unless the boolean variable has the right value (false), so if the function is getting called I must understand that the value is false, but I cannot understand why do the CString buf starts always with "U".
What could you recommend me in order to find out what is happening here?
Thank you in advance, an please excuse me for this large post.
|
|
|
|
|
m_bGraficaTempsReal is initialized? To what?
If it starts as false, and you only click once, won't it be true from then on?
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Of course you are right, that variable is initialized to "true".
But then, in all the application I'm using the value of that variable to fill up the MSChart values, and depending on that value the data come from different sources.
Again, each time I click on the MSChart object I can see how the data changes (the values that fill the MSChart change as they came from different places). That data is filled from an external OnTimer event that checks the value of the boolean variable m_bGraficaTempsReal. Then, if the data insertion changes correctly, and it depends on that boolean value, I do not understand how do the string is not changing.
So the bool variable is initialized, but then the user can click several times to the MSChart object in order to change the values it represent. I'd love to be able to change the labels on each bar of the graph in order to show a change.
Thank you for your feedback.
|
|
|
|
|
hmm...going back to your original post...
Joan Murt wrote: The OnTimer is also dependant and that variable, so SetValor is not being called unless the boolean variable has the right value (false), so if the function is getting called I must understand that the value is false, but I cannot understand why do the CString buf starts always with "U".
Something strange there - If you put a breakpoint at the decision code and a breakpoint in
SetValor then the value should be the same. Is it?
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Yes, this is the strangest thing I've ever seen programming, it should be the same value, but mysteriously it isn't.
I must be making something extremely incorrect, but I cannot find it.
I cannot understand how, if inside the OnTimer event I call SetValor and the code is this:
if (boolvar)<br />
{<br />
SetValor(...<br />
}
Then when I'm inside the function I see the code entering in the first code:
if (!boolvar)<br />
{<br />
FIRST CODE<br />
}<br />
else<br />
{<br />
SECOND CODE<br />
}
This is incredible and I have no clue on how to change that.
Moreover, as I was explaining in the first post, that value is not being changed anywhere else, it only changes after one click in the MSChart object.
[Mod]
Sorry, I've missed to say Thank you!
[/Mod]
|
|
|
|
|
I'm losing sleep over this...
Sorry in advance about the long question
I've got an unformatted binary(.mid) file I want to display as text. When I use fscanf, like this:
*****************************
#include <stdio.h>
int main ()
{
void *list;
int i;
FILE * pFile;
pFile = fopen ("C:/Moondance.mid", "rb");
for(i=1; i<5; i++) //read 4 chars
{
fread(&list, 1, 1, pFile);
printf("%c ", list);
}
list=0;
for(i=1; i<5; i++) // read 4 bytes of decimals
{
fread(&list, 1, 1, pFile);
printf("%x ", list);
}
fclose (pFile);
return 0;
}
************************
it shows a byte at a time like this:
M T h d 0 0 0 6
(file header) (next chunk size)
where 0 0 0 6 is really 00 00 00 06, a 4-byte number
But when I try to replace the "for" number reader code with this:
******
fread(&list, 4, 1, pFile);
printf("%x ", list);
******
I get:
M T h d 6000000
It seems to have switched endedness or read each byte in the wrong order into the pointer.
I want it to print out as just decimal "6"
help?
regzim
|
|
|
|
|
regzim wrote: When I use fscanf, like this...
Are you hiding its usage someplace?
Why do you have list defined as a void* rather than a char ? fread() needs a spot to store the information it reads.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
fread doesn't care at all about 'endianness'.
the 'endianness' here is in the act of treating those four bytes like an integer value.
#include < stdio.h>
int main(int argc, char* argv[])
{
unsigned char b[4] = {1,2,3,4};
unsigned int p = *(unsigned int *)&b[0];
printf("%x", p);
return 0;
}
prints "4030201"
|
|
|
|
|
Aw, crumbs. I meant to write in the fscanf version, but it really doesn't matter. My intended point was that every function (except fread) I have been able to find to read a file either reads it one byte at a time, or needs a delimiter, like a null or so. Sorry about that, David.
Chris- I still don't get it... does that mean anytime I try to put four bytes together into an int to print, it stores it backwards? Was your example intended as the way not to do it, or as the only way to do it? The four-byte 00 00 00 06 is translated as an integer, "6". I could just "is.ignore" the extra zeros, but what if those spaces are filled with hex code for a larger integer?
Thanks for your replies,
regzim
|
|
|
|
|
If you do a binary write of an int to a file, then there are two ways to order the bytes, either msb first or lsb first. As long as you read / write on the same hardware you are OK and you don't need to worry about the endian nature. If you are reading byte by byte, and then want to reconstruct your int you need to know which order they were written. If you transfer binary files between machines with different hardware you can also run into difficulties.
See http://www.cs.umass.edu/~verts/cs32/endian.html[^]
|
|
|
|
|
regzim wrote: Was your example intended as the way not to do it, or as the only way to do it?
it's an example of the way it is: the byte order of an integer in memory is not the same as what you'd write on a piece of paper.
regzim wrote: The four-byte 00 00 00 06 is translated as an integer, "6".
it's translated as an integer, 6000000
regzim wrote: I could just "is.ignore" the extra zeros, but what if those spaces are filled with hex code for a larger integer?
why would an integer value ever have 'extra' data in it? if you only want that one byte, then just read that one byte. if you need all four bytes, you have to correct for byte order and accept all four bytes. right?
|
|
|
|
|
I think I get now that this isn't an endianness issue at all.
>>why would an integer value ever have 'extra' data in it? >>if you only want that one byte, then just read that one >>byte.
well, for example:
00 00 00 06
is simply decimal "6", and the leading zeros are moot. But
f0 09 43 f7
| |
------------
|
(really a 4-byte long int)
(in my context) is a four byte/32 bit unsigned long int that makes for a very large nuber, and every byte is important to the resulting long int value, unlike the previous example's leading zeros. Until I "getc" the data in the file, I don't know what I'm going to get at all but I do know it's going to be four bytes that together represent a long int at any given time. I hope I'm putting this right...
>> if you need all four bytes, you have to correct for byte order and accept all four bytes. right?
Right. And I think I can finally ask a much more succint question than the rambling diatribe I had before:
I need to accept all four bytes at once. How do I correct for byte order?!
P.S. Keep in mind that I'm C++ self taught and there may be some gaps in my knowledge of the fundamentals, so don't assume I already know the most obvious, simple answers...
regzim
|
|
|
|
|
regzim wrote: I need to accept all four bytes at once. How do I correct for byte order?!
if you know for sure that the byte order of the data you've read is in the wrong order, you can use a function like _swab to do it. or, you can use this:
void SwabInt32(__int32 &v)
{
__int32 t;
BYTE* cp = (BYTE*)&v;
t = cp[0] << 24;
t |= cp[1] << 16;
t |= cp[2] << 8;
t |= cp[3];
v=t;
}
that just reverses the order of the bytes in the input __int32.
give it a whirl.
|
|
|
|
|
Ahhhhhh...
God bless you, Chris. In taking apart your code, I've realized I could do one of two things:
1. "fread" 4 bytes at a time into a long variable and reverse the order of bytes
<or>
2. "getc" a byte at a time, and bitwise left-shift them a byte at a time until all four bytes are filled, like so:
{
FILE * pFile; // pointer to the file
unsigned long Value;
Value = getc(pFile); // put first byte in Value Value = (Value << 8) + (getc(pFile)); //move everything over 1 byte
Value = (Value << 8) + (getc(pFile)); //move everything over 1 byte
Value = (Value << 8) + (getc(pFile)); //move everything over 1 byte
printf("Chunk Size: %d\n", Value);
}
This works so far, but I'll have to road test it a little while to see...
THANK YOU for your time! Now I can sleep...
regzim
|
|
|
|
|
sorry about that- screwed up the formatting-
Value = getc(pFile); // put first byte in Value Value = (Value << 8) + (getc(pFile)); //move everything over 1 byte
is supposed to read
Value = getc(pFile); // put first byte in Value
Value = (Value << 8) + (getc(pFile)); //move everything over 1 byte
regzim
|
|
|
|
|
no problem.
just a note on getc v fread: it's generally faster to read as much at a time as you can. with 4 bytes v 1 byte, the difference might not be great, but in general, it's worth the trouble to avoid single-byte reads, if you can do a multi-byte read.
|
|
|
|
|
Hey guys, it has been a while /cry. I seem to be having some issues with comparing values in a file, such as finding the highest value in a file in mixed order and outputting to a file in correct order. I have a file created with the following text 4,3,1,2, my object is to find the highest value then output to a file in correct orsder to 1,2,3,4. This is all I have and I am a little rusty cause it has been a while:
// iofilecomp.cpp : Defines the entry point for the console application.
// iofilecomp.cpp : Explains how to copy the contents from one file to another.
//
#include "stdafx.h"
#include <conio.h>
#include <string>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ifstream ins; //reads from file
ofstream ous; //writes to file
ins.open("in.dat");
ous.open("ou.dat");
string line;
if( ins.is_open )
{
while ( ! ins.eof() )
{
getline(ins, line);
cout << line << endl;
}
ins.close();
}
else cout << "Unable to open file.";
ous.close();
_getch();
return 0;
}
The above will only output in the order read from the file. Possibly could I get some assistance or pointed in the right direction please. Thank you.
|
|
|
|
|
read the file like you do, put the values in a vector , sort the vector and write it back to a file.
|
|
|
|
|