How to decompress CCITT Group 4 Algoritms? - matlab

I'm trying to code decompression CCITT Group4 algorithm using my matlab code editor.
But, I cannot understand decoding mechanism.
when we finish encoding an original binary image, we wil have only encoded binary code.
so, In that code, there are no a0, a1, a2, b1, b2(you know, CCITT G4 elements).
This point is My question. Let me give you an example.
we have compressed code line(0 0 0 1 0 0 1 0 1 1 1 1 1).
Firstly, you can detect "Pass mode codeword(0 0 0 1)",
and "Horizontal mode codeword(0 0 1 0 1 1 1 1 1)".
we can know the decoding code run length about horizontal mode, ("White run length=2 -> 0 1 1 1", "Black run length=2 -> 1 1")
But, How can we know the decoding code run length about pass mode??
I think there is no information about pass mode cord run length. Please let me know. Thank you.

CCITT G4 is a 2-Dimensional image encoding algorithm. The pass code and other codes (e.g. the vertical codes) use the previous line as a reference. After a line is decoded, it becomes the "previous" line and a new "current" line begins.

Related

Error when running G= graph(s,t) in matlab

I want to calculate L = laplacian(G) from a graph dataset. I imported the dataset which contains two columns: FromNodeId and ToNodeId:
# Nodes: 3997962 Edges: 34681189
# FromNodeId ToNodeId
0 1
0 2
0 31
0 73
0 80
0 113619
0 2468556
0 2823829
0 2823833
0 2846857
0 2947898
0 3011654
0 3701688
0 3849377
0 4036524
0 4036525
0 4036527
0 4036529
0 4036531
0 4036533
0 4036534
0 4036536
0 4036537
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
To do so, I need to find G first so I use G = graph(FromNodeId, FromNodeId). When I did that, I got this error:
>> G = graph(fromNodeId,toNodeId)
Error using matlab.internal.graph.MLGraph
Source must be a dense double array of node indices.
Error in matlab.internal.graph.constructFromEdgeList (line 125)
G = underlyingCtor(double(s), double(t), totalNodes);
Error in graph (line 264)
matlab.internal.graph.constructFromEdgeList(...
I don't know why! Can I get a solution of that? Thank you.
Turns out the problem lies in the fact that no zeros are allowed when using the Graph function in this manner. (See: Target must be a dense double array of node indices. How to Solve?)
I downloaded the dataset and ran it successfully with the following code. Note that this code uses a system command and is not compatible with all operating systems, but it should be simple enough to rewrite to whatever operating system you use. It also assumes the .txt file to be in the working directory.
% Removes first lines with comments in them; this system command was tested on Linux Ubuntu 14.04 and is probably not portable to Windows.
% If this system command doesn't work, manually remove the first four lines from the text file.
system('tail -n +5 com-lj.ungraph.txt > delimitedFile.txt');
% Read the newly created delimited file and add 1 to all nodes.
edges=dlmread('delimitedFile.txt')+1;
% Build the graph
G=graph(edges(:,1),edges(:,2));
Assuming you've build your arrays similarly to how I did it, adding 1 to FromNodeIdFull and ToNodeIdFull should resolve your problem. In other words, the following code snippet should solve your problem; if it doesn't I advise you to rewrite based on the code presented above.
G=graph(FromNodeIdFull+1,ToNodeIdFull+1);
Leaving my old answer here, as deleting it may cause confusion for others reading both this answer and the comments to it. Note that the answer below did NOT resolve the issue.
Just putting the comments by myself and NKN into an answer:
The problem lies in the fact that the arrays are sparse but graph() seems to expect full arrays. The following should work:
FromNodeIdFull=full(double(FromNodeId));
ToNodeIdFull=full(double(ToNodeId));
G=graph(FromNodeIdFull,ToNodeIdFull);
Depending on whether your input arrays are already doubles or not you may be able to remove the double() from the first two lines.

read arrays in Simulink

I need some help of solving that issue: I have 5 different voltage values that change every single tick time - that mean every single moment. I need to sort them and after they been sorted I want to go to another matrix(like this one at the bottom) and to pull out(read) specific column from it, for every state pre define(timing that I am designing..) That mechanism change every single states/moment. How can I do this ?
The Matrix look like(and could be greater...):
0 0 0 1 1 1...
0 1 1 0 0 1...
1 0 1 0 1 0...
1 1 0 1 0 0...
.. .. .. .. .. ..
Thanks, Henry
I am not sure I understood it correctly. So I will edit my answer after you make your question a bit more clear.
I see two separate things:
Reading 5 voltage values which change at each step. You want to sort these values. To do this you can use the sort function of matlab. It is really easy to use and you can look at it here.
This is the part I didn't understand well. After sorting the voltage readings what do you want to do with the matrix ? If you want to access just a specific column of the matrix and save it in a variable you can do it in this way. Let's assume you have a matrix A which is N x N, if you want to access the 10th column of the matrix and store it in a variable called column10 you will do something like: column10 = A(:,10)
I hope this will help you but let me know if this is what you wanted and I will edit my answer according to it.
Fab.

How to encode packet information by XOR in matlab

I am working in channel coding part. My major is encoding with bit information. For example, given a input bit is x=[1 0 1] and G matrix is
G =
1 0 0 1
0 0 1 0
1 1 0 1
then encoding symbol will be y=mod(x*G,2)% mod to convert to binary bit
y =
0 1 0 0
It is very simple idea for bits encoding processing in channel coding. Now I want to do map this work to packet encoding. Some paper mentioned that we can do this way for packet encoding if we consider each packet is n bytes. For example, I have a text file that size is 3000bytes. Now I will divide the file into 1000 packet. Hence, each packet has size is that 3 bytes. My problem is that I done with bit encoding. However, I don't have any idea to work with packet encoding. Please let me know if you worked with this problem. I hear that bit encoding we only has two level 0 and 1, so we can use GF=2. If we work for packet level, we must consider GF>2. I am not sure it
Second question is that how about if packet size equals 50 bytes instead of 3 bytes?
First, when you talk about GF(p^m), you mean Galois Field, where p is a prime number that indicates the degree of the polynomial. Hence, it is possible to define a field with pm elements. In your case, p=2 and m=3. Once, you have the polynomial, you can apply it using two different encoding schemes:
Block coding. You can split the packet into several blocks of 3 bits and encode each block independently. Use zero-padding in case they are not multiples.
Convolutional coding. You apply the polynomial as a sliding algorithm.
The second approach is more robust and has lower delays.
The GF terminology is used to work with polynomials, the concepts of extended Galois Fields and polynomials are not very complicated, but it takes time to understand it. However, in practice, if you have a polynomial expression you just apply it to the bit sequence in the fashion that you want, block or convolutional (or fountain).
You matrix G is actually defining 4 polynomials for the input X=[1 x x^2], namely Y1=1+x^2, Y2=x^2 and Y3=x, Y4=1+x^2

comparing images matlab

Ok so let's say i have a binary image containing the pixel representation for 1,2,A,B or whatever. But for now let's just consider 1
0 0 0 0
0 1 1 0
0 1 1 0
0 1 1 0
0 1 1 0
0 0 0 0
and then i have another image containing the standard representation of 1.
Now what i wan't is to compare these two images and decide whether my first image contains pixel values for 1 or not.
What kind of algorithms are available at my disposal ?
Please i do not require the name of the matlab function for image comparison as has been the answer for similar questions. Rather than that i require the name of some algorithms that can be used to solve this problem so that i can implement it on my own in C#
What you need to compute is the distance between your image and the ground truth. This distance can be stated in many different ways. Search google for similarity measures on binary data. See here a review.

Generate multiple output files starting from a single "seed" file

Good Morning everybody,
it's sometime I wonder if it is possible to do something close to what I'm gonna describe by means of Matlab:
Using an external tool (i.e. Ansys, Abaqus or other software) I engender a "seed" listed (file extension .inp, .db or others) file which will be used as reference for the next steps;
Starting from this seed listed file, I would like to get, let's say, 200 similar project files, containing some slight variations compared to the seed: I mean, for instance, simulation time or any other characteristic.
I will give a short example: I'm currently working on Bladed, software perfoming aero-elastic simulation for wind energy applications; Blade gives me, for instance, the chance to generate turbulent wind fields. The seed code would be the one shown below:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<BladedProject version="4.2.0.46">
<BladedData dataFormat="project">
<![CDATA[
VERSION 4.2.0.46
MULTIBODY 1
CALCULATION 3
OPTIONS 0
PROJNAME
DATE
ENGINEER
NOTES ""
PASSWORD
MSTART WINDND
SPMODEL 7
NLAT 31
NVER 45
LATDIM 150
VERDIM 220
LONGLS 340.2
LATLS 42.1482
VERTLS 42.1467
XLV 113.4
YLV 66.3117
ZLV 33.1546
XLW 27.72
YLW 25.228
ZLW 50.4542
LAMBDA1 0
CohScale 340.2
COHDEC 12
SCALE 0
GAMMA 0
YDIML 0
N2 0
YDIMS 0
K1MIN 3
LENGTH 1830
STEP .2233905
UBAR 3
SEED 3
OUTFILE l:\02_turb_dev\50-1\loads\50-1_D116_Validation_adapted_to_AV07\wind\DLC1-2_Kaimal\s1\3.wnd
DIAM 0
HUBHT 0
TURBHTTYPE 0
TURBBOTTOM 0
GUSTAVT 0
GUSTSPEED 0
TOLERANCE 0
DLONGMIN 0
DLONGMAX 0
Z0MIN 0
Z0MAX 0
MAXITER 14
MAXSEED 100
NFILES 1
UseWindShear 0
UseShearToGust 0
WVMODEL 0
MATCHFILE ''
SPACING 0
SAMPLEFREQ 0
MEANSPEED 0
ILAT 0
IVERT 0
GUSTMETHOD 0
DLONG 0
ILAT 0
IVERT 0
LONGGUST 0
LATGUST 0
VERTGUST 0
iLONGGUST 0
iLATGUST 0
iVERTGUST 0
PEAKINESS 0
MAXFRAN 0
MEND
0WINDND
]]>
</BladedData>
</BladedProject>
By means of matlab I would like to be able to generate similar project files for different wind speeds and random seeds (UBAR,SEED) and to save these files in a predetermined sub-folder.
Finally, I only would be glad to know if any of you has a clue/advice to give me.
Then, it will be my task to find out a proper architecture for coding.
I thank you all in advance for supporting.
Best regards,
Francesco
So here are some bits and pieces of an answer, read more about the functions used in the Matlab documentation. The code below is only an example, but you shouldn't have any trouble expanding it. This code will write 5 files with UBAR values 1..5. I'll suppose that, at the start of execution, your current working directory is a suitable place for those 5 files to reside, at least temporarily
for ubar = 1:5 %using the name of the variable as the iteration variable here
fname = ['bladefile' num2str(ubar) '.txt'] % filenames will be bladefile1.txt etc
fid = fopen(fname,'w') % open the file for writing, keep the file id for later reference
fprintf(fid, '<?xml version="1.0" encoding="ISO-8859-1" ?>\n<BladedProject version="4.2.0.46">\n <BladedData dataFormat="project">\n <![CDATA[\n')
This fprintf call writes to the output file (using the file id fid); it writes your XML header. Note the embedded \ns which will be turned into new lines in the output file.
fprintf(fid, 'VERSION 4.2.0.46\n') % note, again, the trailing newline so the next line of output starts on a new line
...
fprintf(fid, 'ubar %i\n', ubar)
This call to fprintf writes the string ubar to the file, then the %i indicates that an integer will be written, and the value of that integer will be taken from the variable ubar.
And so on until the end of the loop
fclose(fid)
end % and loop around
This should get you started and, if your aim is only to write a set of output files once, is good enough for throwaway use.
If you expect to re-use the code do as you would in any programming language and wrap it up into a function. For example, you could write a function which takes a value for ubar and a value for seed as inputs and writes the file, something like this;
for ubar = 1:5
for seed = 1:7
write_inp_file(ubar,seed)
end
end