Binary representation of digits - matlab

I want to represent any digit in 8*12 matrix as a sample
4 be equal
00000000
00000000
00000000
00001000
00011000
00101000
01111110
00001000
00001000
00000000
do you have any suggestion of how or where can I get all digits without I spend time to make them .
appreciate any help
tnx

finnaly I do it manually , left this for future,maybe achive somebody need :(
p=cell(1,10);
p{10}=[
0 0 0 0 0 0 0 0;
0 1 1 1 1 1 1 0;
0 1 0 0 0 0 1 0;
0 1 0 0 0 0 1 0;
0 1 0 0 0 0 1 0;
0 1 0 0 0 0 1 0;
0 1 0 0 0 0 1 0;
0 1 0 0 0 0 1 0;
0 1 0 0 0 0 1 0;
0 1 0 0 0 0 1 0;
0 1 1 1 1 1 1 0;
0 0 0 0 0 0 0 0;
];
p{1}=[
0 0 0 0 0 0 0 0;
0 0 0 0 1 0 0 0;
0 0 0 1 1 0 0 0;
0 0 1 0 1 0 0 0;
0 0 0 0 1 0 0 0;
0 0 0 0 1 0 0 0;
0 0 0 0 1 0 0 0;
0 0 0 0 1 0 0 0;
0 0 0 0 1 0 0 0;
0 0 0 0 1 0 0 0;
0 0 0 1 1 1 0 0;
0 0 0 0 0 0 0 0;
];
p{2}=[
0 0 0 0 0 0 0 0;
0 1 1 1 1 1 1 0;
0 0 0 0 0 0 1 0;
0 0 0 0 0 0 1 0;
0 0 0 0 0 0 1 0;
0 0 0 0 0 0 1 0;
0 1 1 1 1 1 1 0;
0 1 0 0 0 0 0 0;
0 1 0 0 0 0 0 0;
0 1 0 0 0 0 0 0;
0 1 1 1 1 1 1 0;
0 0 0 0 0 0 0 0;
];
p{3}=[
0 0 0 0 0 0 0 0;
0 1 1 1 1 1 1 0;
0 0 0 0 0 0 1 0;
0 0 0 0 0 0 1 0;
0 0 0 0 0 0 1 0;
0 0 0 0 0 0 1 0;
0 1 1 1 1 1 1 0;
0 0 0 0 0 0 1 0;
0 0 0 0 0 0 1 0;
0 0 0 0 0 0 1 0;
0 1 1 1 1 1 1 0;
0 0 0 0 0 0 0 0;
];
p{4}=[
0 0 0 0 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1 1 0;
0 0 0 0 0 0 0 0;
];
p{9}=[
0 0 0 0 0 0 0 0;
0 1 1 1 1 1 1 0;
0 1 0 0 0 0 1 0;
0 1 0 0 0 0 1 0;
0 1 0 0 0 0 1 0;
0 1 0 0 0 0 1 0;
0 1 1 1 1 1 1 0;
0 0 0 0 0 0 1 0;
0 0 0 0 0 0 1 0;
0 0 0 0 0 0 1 0;
0 1 1 1 1 1 1 0;
0 0 0 0 0 0 0 0;
];

Note that font design started out with these problems, digitized approximations of letters. Finding readable digits with such a coarse representation will be difficult.
Even if you could find a solution by computer solution, it would surely need to be hand tuned for good looks. And for only a few digits, just do it entirely by hand and be done with it.

You can use bitmap font editor like 'CV_fonted.exe' from
https://forum.crystalfontz.com/showthread.php?3619-Bitmap-font-editor-for-graphic-LCD
Then save as ANSI C format. After some process on the file, you can get your result.

Related

matlab morphological closing with imdilate and imerode

In the the matlab documentation there is this sentence about closing an image with imclose:
The morphological close operation is a dilation followed by an
erosion, using the same structuring element for both operations
I tried it out but the result is not the same. Can sombody tell me how I can close an image only with imdilate and imerode?
I = [0 0 0 0 0 0 0 0;
0 0 1 1 1 0 0 0;
0 0 0 1 1 1 0 0;
0 1 1 1 0 0 1 0;
0 0 1 0 0 1 1 0;
0 1 0 0 1 0 1 0;
0 0 1 0 1 0 1 0;
0 0 0 0 0 0 0 0];
Q = [0 1 0; 0 1 0; 0 1 1];
Q_n = [1 1 0; 0 1 0; 0 1 0];
J = imclose(I,Q)
D = imdilate(I,Q);
S = imerode(D,Q)
Closed result:
0 0 0 0 0 0 0 0
0 0 1 1 1 0 0 0
0 0 1 1 1 1 0 0
0 1 1 1 1 1 1 0
0 1 1 1 1 1 1 0
0 1 0 0 1 1 1 0
0 0 1 0 1 1 1 0
0 0 0 0 0 0 0 0
dilate and then erode:
0 0 1 1 1 0 0 0
0 0 1 1 1 0 0 0
0 0 1 1 1 1 0 0
0 1 1 1 1 1 1 0
0 1 1 1 1 1 1 0
0 1 0 0 1 1 1 1
0 0 1 0 1 1 1 1
0 0 1 0 1 1 1 1

Comparison between two rows and change value

i have a matrix 20 rows and 20 columns,
If the value 1 in the row 5 the column take 0
matric=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ;
0 1 1 1 1 0 1 0 1 0 1 1 1 0 1 0 1 1 1 1;
0 1 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 1 0 1;
0 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 1 0 1;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;];
if (matric(5,:)==1)
matric(1:5,1:end)=0;end
I try to compare the second row and the 5 row
If we have "1" in row 2 and row 5
The row 2 take 0
if (matric(5,:)==matric(2,:)==1)
matric(2,1:end)=0;end
do you have an idea
Thank you
The desired output is:
matric=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
1 0 1 1 0 0 1 1 1 1 0 1 0 1 1 1 1 0 1 0 ;2row will change
0 1 1 1 1 0 1 0 1 0 1 1 1 0 1 0 1 1 1 1;
0 1 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 1 0 1;
0 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 1 0 1; % 5 row
You can use logical indexing.
I strongly encourage you to read the following references:
Mathworks documentation page: Find Array Elements That Meet a Condition
Loren on the Art of MATLAB blog entry: Logical Indexing – Multiple
Conditions
Use the following lines of code:
Put 0 in all those columns that have a value of 1 in row 5:
matric(:, matric(5, :) == 1) = 0;
Put 0 in all those columns of row 2 that have a value of 1 both in rows 2 and 5:
matric(2, matric(2, :) == matric(5, :)) = 0;
You can use logical indexing to achieve this. Now I must say I am a bit confused by what exactly you want to achieve based on your description, but based on the your code the first statement can be done as follow:
matric(1:5,matric(5,:)==1) = 0;
and the second would look like:
matric(2,matric(5,:)==1 & matric(2,:)==1)=0;

MxN matrix with ones and zeros following a specific rule

I want to create a MxN matrix as shown below:
[1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1]
I have window size, let's say, 5 and it moves 3 in every row. Is it possible to create such a matrix without using for loops? Or is there any optimum way to do it?
This is a one line solution:
reshape([reshape([ones(5,6);zeros(21,6)], 1,[]), ones(1,5)],[],7).'
note:
The desired matrix can be seen as concatenation of a [6, 5+21] matrix:
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
and a [1 ,5] matrix:
1 1 1 1 1
that reshaped to a [7 , 23] matrix.
Other solution using repelem + bsxfun + accumarray:
r = repelem (1:7,5);
c= bsxfun(#plus, ((1:5)-3).',3*(1:7));
out = accumarray([r(:) c(:)] ,1)
Indices of rows and columns of 1 s can be generated and accumarray can be used to create the desired matrix.

character or pattern recognition [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm trying to make a character recognition using linear network but I'm getting some error when running my code, anyone who can help me with a single or basic explanation or how I can go about it? below is my code
A1 = [ 0 0 1 1 0 0 0;
0 0 0 1 0 0 0;
0 0 0 1 0 0 0;
0 0 1 0 1 0 0;
0 0 1 0 1 0 0;
0 1 1 1 1 1 0;
0 1 0 0 0 1 0;
0 1 0 0 0 1 0;
1 1 1 0 1 1 1];
B1 = [ 1 1 1 1 1 1 1;
1 0 0 0 0 0 1;
1 0 0 0 0 0 1;
1 0 0 0 0 0 1;
1 1 1 1 1 1 1;
1 0 0 0 0 0 1;
1 0 0 0 0 0 1;
1 0 0 0 0 0 1;
1 1 1 1 1 1 1];
C1 = [ 0 0 1 1 1 1 1;
0 1 0 0 0 0 1;
1 0 0 0 0 0 0;
1 0 0 0 0 0 0;
1 0 0 0 0 0 0;
1 0 0 0 0 0 0;
1 0 0 0 0 0 0;
0 1 0 0 0 0 1;
0 0 1 1 1 1 0];
A2 = [ 0 0 0 1 0 0 0;
0 0 0 1 0 0 0;
0 0 0 1 0 0 0;
0 0 1 0 1 0 0;
0 0 1 0 1 0 0;
0 1 0 0 0 1 0;
0 1 1 1 1 1 0;
0 1 0 0 0 1 0;
0 1 0 0 0 1 0];
B2 = [ 1 1 1 1 1 1 0;
1 0 0 0 0 0 1;
1 0 0 0 0 0 1;
1 0 0 0 0 0 1;
1 1 1 1 1 1 0;
1 0 0 0 0 0 1;
1 0 0 0 0 0 1;
1 0 0 0 0 0 1;
1 1 1 1 1 1 0];
C2 = [ 0 0 1 1 1 0 0;
0 1 0 0 0 1 0;
1 0 0 0 0 0 1;
1 0 0 0 0 0 0;
1 0 0 0 0 0 0;
1 0 0 0 0 0 0;
1 0 0 0 0 0 1;
0 1 0 0 0 1 0;
0 0 1 1 1 0 0];
p = [A1(1:end); B1(1:end); C1(1:end)]';
t = [A2(1:end); B2(1:end); C2(1:end)]';
net = newlin(minmax(p),1);
net.trainParam.goal = 10e-5;
net.trainParam.epochs = 500;
net = train(net, p, t);
my error is on line 62 and the code on line 62 is
net = train(net, p, t);
anyone with a good example or how i can make this code run?thanks in advance im trying to learn and im new to matlab
I ran the code and the error states: Output data size does not match net.outputs{1}.size.
Check the format for matrix sizes. I think that is the issue.

error with matrix inverse only when matrix created through script

A=[ 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
1 -3 1 0 0 0 0 0 0 1 0 0 0 0 0 0;
0 1 -3 1 0 0 0 0 0 0 1 0 0 0 0 0;
0 0 1 -7.94E+05 7.94E+05 0 0 0 0 0 0 2 0 0 0 0;
0 0 0 +7.94E+05 -7.94E+05 1 0 0 0 0 0 0 2 0 0 0;
0 0 0 0 1 -3 1 0 0 0 0 0 0 1 0 0;
0 0 0 0 0 1 -3 1 0 0 0 0 0 0 1 0;
0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0;
0 1 0 0 0 0 0 0 1 -3 1 0 0 0 0 0;
0 0 1 0 0 0 0 0 0 1 -3 1 0 0 0 0;
0 0 0 2 0 0 0 0 0 0 1 -7.94E+05 7.94E+05 0 0 0;
0 0 0 0 2 0 0 0 0 0 0 7.94E+05 -7.94E+05 1 0 0;
0 0 0 0 0 1 0 0 0 0 0 0 1 -3 1 0;
0 0 0 0 0 0 1 0 0 0 0 0 0 1 -3 1;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1];
This matrix has an inverse when created manually. But the same matrix when generated through script and inverted gives me "Matrix is close to singular or badly scaled. Results may be inaccurate." error and the inverse generated is not the same as inv(A). I tried using the backslash too. I tried creating the matrix through program using format long, short and bank and continue to face the same problem. What could be my mistake? Thanks in advance.