how to solve Error Output argument "variable_name" (and maybe others) not assigned during call to "function_name".

4 views (last 30 days)
Bachtiar Muhammad Lubis
Bachtiar Muhammad Lubis on 13 Jan 2019
Answered: Jan on 14 Jan 2019
Good evening to all my brothers and sisters. my codes give some issue that confuse me.
these the codes are:
Img = imread('Adok_Karo1_biner.jpg');
BW = im2bw(Img, graythresh(Img));
BW = bwareaopen(BW, 5);
re = BW;
while 1
%Fcn 'lines' separate lines in text
[fl, re]=lines(re);
imgn=fl
%% Fcn projProfile_Horizontal separate characters in line
[char_out, num_char, L, Ne] = projProfile_Horizontal(imgn);
%% end
set(handles.text11, 'String',Ne);
%% Objects extraction
NumberOfCharacter = length(num_char); % number of characters in a line That had been stored in cell Num
for m = 1 : Ne % Ne is Number of labelled object
if Ne == 2
L1 = ismember(L, 1); % storing the labelled object 1 to L1
L2 = ismember(L, 2); % storing the labelled object 2 to L2
char_out = L1; % first object on a cropped character window
char_out2 = L2; % second object on a cropped character window
figure();
%showing first object
subplot(1, 2, 1);
imshow(char_out);
caption = sprintf('character #%d', 1);
title(caption, 'FontSize', 20);
%Showing second object
subplot(1,2,2);
imshow(char_out2);
caption2 = sprintf('character #%d', 2);
title(caption2, 'FontSize', 20);
end
end
%% End
BW2 = bwmorph(char_out,'thin',Inf);
imrotate(BW2,0);
imshow(~BW2);
z=imresize(BW2,[50 50]);
%z = imresize(BW2, [42 24]); % [m, n] format
z = feature_extract(z); % Image Zoning 3x3
FeatureOutTest = z; % new modified
save('FeatureOutTest.mat','FeatureOutTest'); % new modified
test
pause(0.5);
% end
if isempty(re) %See variable 're' in Fcn 'lines'!
%To stop "while" iteration when there aren't any remaining-
%character and off course the line itself in "re" image
break;
end
end
and function for projProfile_Horizontal. m is :
function [char_out, num_char, L, Ne] = projProfile_Horizontal(areaOpeningImage)
%% projProfile_Horizontal is used to separate text line image into characters based on its horizontal projection
% char_out : a character output.
% num_char : number character in text line image.
% L : labelled characters in a cropped image window, so that we know how many image
% in a cropped image window.
% Ne : number of labelled object in a cropped image window
%%
%clc; % Clear the command window.
%close all; % Close all figures (except those of imtool.)
% clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
%areaOpeningImage =imread('D:\pcd\tester\Segmentation\data_test\ImageAnalyst\Adok_karo1_biner.jpg');
% Show image
figure(1)
h1 = subplot(4, 12, 1:12);
imshow(areaOpeningImage);
impixelinfo
title('INPUT IMAGE WITH NOISE')
%% Convert to gray scale
if size(areaOpeningImage, 3) == 3 % RGB image
areaOpeningImage=rgb2gray(areaOpeningImage);
threshold = graythresh(areaOpeningImage);
binaryImage = im2bw(areaOpeningImage, threshold);
imshow(binaryImage);
axis('image', 'on'); % Display tick marks.
title('Binary Image', 'FontSize', fontSize);
end
%% Find horizontal profile
binaryImage = areaOpeningImage; % Area Opening Image is assumed euqal to binaryImage :D (just a name)
h2 = subplot(4, 12, 13:24);
horizontalProfile = sum(binaryImage, 1);
plot(horizontalProfile, 'b-');
title('Horizontal Profile', 'FontSize', fontSize);
grid on;
%%
%% Find dividing lines between the characters.
props = regionprops(horizontalProfile == 0, 'Centroid'); %centroid of all gaps
xyCentroids = [props.Centroid];
dividingLines = xyCentroids(1:2:end); % get only the gaps centroid
for k = 1 : length(dividingLines)
thisX = dividingLines(k);
%line(h1, [thisX, thisX], ylim(h1), 'Color', 'r');
line([thisX, thisX], ylim(h1), 'Parent', h1, 'Color', 'r');
%line(h2, [thisX, thisX], ylim(h2), 'Color', 'r');
line([thisX, thisX], ylim(h2), 'Parent', h2, 'Color', 'r');
end
%%
%% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0.05, 1, 0.95]);
drawnow;
%%
%% Extract each letter.
fontSize = 12;
num_char = {};
char_coord = 1;
for k = 1 : length(dividingLines) - 1
thisX = round(dividingLines(k));
nextX = round(dividingLines(k+1));
subplot(4, 12, 24 + k);
thisLetter = binaryImage(:, thisX:nextX);
[L, Ne] = bwlabel(thisLetter);
char_unpads = pads_crop(thisLetter);
char_pads = padarray(char_unpads,[2 2], 'both');
imshow(thisLetter);
caption = sprintf('Letter #%d', k);
title(caption, 'FontSize', fontSize);
char_out = char_pads;
num_char{1, char_coord} = {num_char, char_out}; % storing all characters into cell
char_coord = char_coord + 1; % plus the coordinat by 1
break; % new editted, so that only take a word per line
end
%%
end
function img_out = pads_crop(thisCharacter)
% cropping the pads
[f, c]=find(thisCharacter); % finding row(f) and column(c) indices
img_out=thisCharacter(min(f):max(f),min(c):max(c));%Cropping all pad of image
% end
end
The Error is :
Output argument "char_out" (and maybe others) not assigned during call to "projProfile_Horizontal".
Error in DetectAksara>btnRecognize_Callback (line 352)
[char_out, num_char, L, Ne] = projProfile_Horizontal(imgn);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in DetectAksara (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)DetectAksara('btnRecognize_Callback',hObject,eventdata,guidata(hObject))
352 [char_out, num_char, L, Ne] = projProfile_Horizontal(imgn);
i had looked at the projProfile_Horizontal function and ran it separately, but it worked properly.
what should i do to solve this error ?

Answers (1)

Jan
Jan on 14 Jan 2019
If length(dividingLines) - 1 equals 0, the loop is not entered and char_out is not created.
Use the debugger to find out, what's going on: Set a breakpoint in the first line of the failing function and step through the code line by line. Then you will see directly, why the output is not defined.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!