|
If you want to test your algorithm out on an image, I would suggest that you try it against a RAW image file. RAW does what it says - it provides the raw data so you can test your compression against uncompressed data.
This space for rent
|
|
|
|
|
Just pass the bytes representing the image to the encoder. If your input parameter is actually a string, replace it by passing a byte array and the length and adapt the code as necessary (replace char by byte and use the passed length instead of the string length). Just think of a string as an array of charaters (one or two bytes per character) and a length. Then you will recognise that there is no big difference (no difference at all when the string class uses one byte per character).
|
|
|
|
|
I tried.But ı was not succesful May you help me ?.I am not good in c#.I am new.I want to do this ı want to understand.Can ı send you my project ?
|
|
|
|
|
Post the relevant (short) code snippets here (you can edit your initial question and add it there) and explain what you have tried and where you got stuck. So you will get the best help because many people can read it.
|
|
|
|
|
I am not good c# actually.I reliazed huffman with c# but whihc compress only text. not image.how can ı do that.İf you want ı can sedn my project MAybe you can help me
|
|
|
|
|
I'm sorry but I did not provide private help here (and others won't do it too). This is a public forum where questions are answered public.
So follow my advices from my previous post and provide more details.
|
|
|
|
|
[Huffman Compressor]
My program is blow the link.This program only comrpess text.What do ı add this program and then which can compress an image for example jpeg.May you investigate my program
|
|
|
|
|
Rıza Berkay Ayçelebi wrote: This program only comrpess text. It works the same for any set of bytes, so it will not "just work" on text only. Text, pictures, sounds, applications; all just a series of bytes.
You still have not answered my question
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
I want to compress picture.I compressed text wiht huffman but how can ı do for pictures ?
|
|
|
|
|
There are problems.
I see that you store the frequency of characters in the header as bytes. That's wrong on both counts. You shouldn't store the frequency because there are multiple valid Huffman trees for almost every set of frequencies (you should therefore, and every format that uses Huffman codes does this, use Canonical Huffman codes[^] and store only the symbol lengths). Storing the frequency as a byte will obviously fail for larger files - images are likely to be large, but this wouldn't have worked for large text files either. Of course if you change to canonical codes and storing the symbol length, it will fit in a byte just fine.
Now moving on to things that aren't actually incorrect but are point for improvement, you don't need (and therefore shouldn't use) single-bit reads and writes. For encoding, just collect the pattern/length of every symbol in a little array and then use something like (not tested, just to get the idea)
uint buffer = 0;
int bitsInBuffer = 0;
foreach (var symbol in imageOrWhatever) {
buffer = (buffer << lengths[symbol]) | pattern[symbol];
bitsInBuffer += lengths[symbol];
while (bitsInBuffer >= 8) {
output.WriteByte((byte)(buffer >> (bitsInBuffer - 8));
bitsInBuffer -= 8;
}
}
Or you can change it to not even do byte-IO either and do proper block IO. This code of course assumes that codes are 25 bits max (otherwise appending a code to the buffer can push something out that hasn't been saved), which is longer than you need, but you could use an ulong as buffer.
For decoding you can use a (big) array that has, for every index, what the first symbol (and its length) are if the index is interpreted as a string of Huffman encoded symbols. This array is easy to build and even easier to use, but depending on your maximum code length it can get pretty big. There are more sophisticated techniques that get the size of the array down, but it's a good start.
This sort of thing is why formats that use Huffman coding specify a maximum code length that isn't too long, for example DEFLATE allows lengths up to and including 15 bits.
|
|
|
|
|
how ı can change sorry ı am not very good in c#
|
|
|
|
|
Your C# skill isn't really the problem here. The problems are more fundamental.
|
|
|
|
|
I am not good in c# I said aldready.But I can create program with c#.I want someone shows how to do it over my codes.I aldready sent my project.My project only take text.
|
|
|
|
|
..works only for text, because you are feeding it a string. You can feed it any bytes, but most images are already compressed - so yes, the result would often be larger than what you started with.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Did you even look at the link I put above?
This space for rent
|
|
|
|
|
I saw the link.I dont have a problems how to code huffman .I aldready coded but ı didnt comrpess image.Can this huffman code compress an image ?
|
|
|
|
|
You obviously didn't read the link. It's encoding images.
This space for rent
|
|
|
|
|
I aldready created huffman code just ı want to learn why my codes compress only text.Can ı use your codes?
|
|
|
|
|
What do you mean with "cannot compress image"? What kind of image? How large, how many colors?
Something like a jpg would already be compressed, so I would not be surprised if it does not actually compress much there.
If you have a bitmap with large repeating spaces, then huff may puff a few bits of it.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
As Eddy has already said: most images are already compressed, and pretty solidly. Compressing compressed data rarely achieves significant result, and often increases the size of the output file, due to the overhead the compression algorithm has to add.
And if you think anyone is going to download your whole project just to tell you that again, you need to rethink your position in the world - it's not as high as you seem to believe...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Rıza Berkay Ayçelebi wrote: I can comrpess text wiht this program but how can ı compres picture ? You compress pictures in the same way as text.
The computer does not distinguish between text and pictures on that level. You may be interested in the Wikipedia articles that explain how JPEG works, since it is a different approach to achieve a similar endresult.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
In my current project, I need to do some calculations in 3d space, like calculating intersection points of lines with planes, determining if a point is inside a triangle / rectangle / (flat) polygone etc.
The Systems.Windows.Media.Media3D namespace offers some functionality for those purposes like cross and dot products of 3d vectors. Sadly, I cannot find good tutorials on the functionality of that namespace - most tutorials deal with drawing which is not relevant for me. And many Google searches point to functionality of the Xna namespace - which seems unavailable on Windows 8 / 10.
Are there other "common" namespaces in the .Net framework for such calculations?
Or do you know good tutorials for calculations with Media3d?
|
|
|
|
|
You might want to look at Math.NET[^] - particularly Math.NET Spatial[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|