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
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.
When I run a code it shows error using vertcat in the marked line. What does it mean and how to change it?
f = [-10 -20 -40 -10 -10 80 70 90];
A = [ 1 1 2 1 3 0 0 0 -----> vertcat error
2 1 3 2 2 0 0 0
1 2 1 1 0 0 0 0
-1 0 0 0 0 1 1 1
0-1 0 0 0 1 1 1
0 0-1 0 0 1 0 0
0 0 0-1 0 0 1 0
0 0 0 0-1 0 0 1];
b = [800 600 900 0 0 0 0 0];
ub = [inf inf inf inf inf 90 57 93];
lb = zeros(8,1);
[x fval]=linprog(-f,A,b,[],[],lb,ub);
A was missing some spaces. This should work:
A = [ 1 1 2 1 3 0 0 0;
2 1 3 2 2 0 0 0;
1 2 1 1 0 0 0 0;
-1 0 0 0 0 1 1 1;
0 -1 0 0 0 1 1 1;
0 0 -1 0 0 1 0 0;
0 0 0 -1 0 0 1 0;
0 0 0 0 -1 0 0 1]
A =
1 1 2 1 3 0 0 0
2 1 3 2 2 0 0 0
1 2 1 1 0 0 0 0
-1 0 0 0 0 1 1 1
0 -1 0 0 0 1 1 1
0 0 -1 0 0 1 0 0
0 0 0 -1 0 0 1 0
0 0 0 0 -1 0 0 1
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}=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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.
I'm building a Matlab GUI which let the user use some interactive tools for image processing (a single mfile with no fig file),
like rotation of the image with imrotate and angle parameter and clearing out pixels with bwareaopen and area parameter.
At first, I was thinking of plotting the tools with my mfile with somehthing like
function myGUI( grayI )
h_fig = figure;
h_ax = imshow( grayI );
title('Drag line and press button to rotate image');
ImgSize = size(grayI);
h_lev = imline(gca, [ 0.2*ImgSize(2), 0.1*ImgSize(1); ...
0.8*ImgSize(2) 0.1*ImgSize(1) ] );
h_lev.addNewPositionCallback( #LineUpdateFcn );
% text for the angle
h_txt = uicontrol('Style','text','String','Angle = []', 'unit', 'norm', ...
'pos',[0 0.9 .1 .05]);
%add rotate button
h_btn = uicontrol('unit','norm','pos',[0 0.95 .1 .05]);
set(h_btn,'string','Rotate','callback',#RotateImageWithLever);
% save the elements data in figure
setappdata(h_fig,'h_lev',h_lev);
setappdata(h_fig,'h_ax',h_ax);
setappdata(h_fig,'h_txt',h_txt);
% wait for user to close figure
waitfor( h_fig );
but then I came across the design of toolbar as built-in class in FileExchange Fireworks and thought maybe I'm missing the right-and-neat way to design my toolbar with classes and built in uitoolbar command.
Any advice on designing my toolbar from single mfile?
Using a custom toolbar would probably be a good solution for the tool you describe. Create the toolbar using UITOOLBAR and add push or toggle buttons using UIPUSHTOOL and UITOOGLETOOL, respectively. This can readily be done in the initialization stage of your GUI m-file.
I've given a simple example below. Some caveats:
The logic of the toggle button vs. push button is not implemented correctly since inverting the image, flipping it and then inverting again will not give the correct result. However, I am just trying to show how to code toolbar buttons not how to process images.
You will probably want to use more creative icons then what I've given in the CData property.
I encourage a object-oriented approach to this solution despite my procedural example.
Here it is:
function myGUI(grayI)
persistent grayICopy;
%# Keep a persistent copy of the image data to be used in the toolbar tool
%# callbacks. Other possibilities here are to not store this data
%# persistently and instead read it from the plotted values or restructure
%# this whole code as a class and store the raw image data in a class
%# property.
grayICopy = grayI;
%# Create the figure window and show the image.
hFigure = figure;
hAxes = axes('Parent', hFigure);
image(grayI, 'Parent', hAxes); %# I don't have the Image processing Toolbox
%# Create toolbar
hToolbar = uitoolbar('Parent', hFigure);
%# Add a toolbar button for 90deg clockwise rotation
uipushtool('Parent', hToolbar, ...
'ClickedCallback', #flipVertical, ...
'CData', ...
repmat([0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0; ...
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0; ...
0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 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], [1 1 3]));
%# Add a toolbar toggle button for inverting image
uitoggletool('Parent', hToolbar, ...
'OnCallback', #toggleInverseOn, ...
'OffCallback', #toggleInverseOff, ...
'CData', ...
repmat([0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0; ...
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0; ...
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0; ...
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], [1 1 3]));
function flipVertical(src, eventdata)
grayICopy = flipdim(grayICopy, 1);
image(grayICopy, 'Parent', hAxes);
end
function toggleInverseOn(src, eventdata)
image(1-grayICopy, 'Parent', hAxes);
end
function toggleInverseOff(src, eventdata)
image(grayICopy, 'Parent', hAxes);
end
end