% makeLookUp - Function to organise look up table from grayvalue to characters % - Part of setUpCmatscii.m % Usage: % grayLookUp = makeLookUp(data,intensity,textWdHgt,oldGLU,showChar) % % Arguments: % data - a structure containing character and its avg intensity % intensity - mean intensity of characters in original 2D space % textWdHgt - [textWidth textHeight] % oldGLU - exisiting grayLookUp table, new data to be added in % showChar - 1 to show characters added in system in progress % % Output: % grayLookUp - look up table from grayvalue to characters % grayLookUp{n} has characters of intensity = (n-1), n=[1:256] % grayLookUp{257} = I, sorted available intensity values % grayLookUp{258} = table, picture of chars arranged according to intensity % grayLookUp{259} = textWidthHeight % grayLookUp{260} = numCharTotal; % Author: % Tzu Yen Wong % wongt AT csse DOT uwa DOT edu DOT au % Department of Computer Science & Software Engineering % The University of Western Australia % % Mar 2004 %1234567890123456789012345678901234567890123456789012345678901234567890123456789 function grayLookUp = makeLookUp(data,intensity,textWdHgt,oldGLU,showChar) %MMMMMM Setting up optional arguments and default values MMMMMM eval('oldGLU;','oldGLU={};') eval('showChar;','showChar=0;') if isempty(oldGLU), warning('new grayLookUp table generated'); elseif length(oldGLU)<259, warning('invalid grayLookUp table supplied, new grayLookUp table generated') oldGLU={}; end textW = textWdHgt(1); textH = textWdHgt(2); numCharTotal = 0; % for displaying chars arranged according to intensity numRow=50; numBigCol = 6; charPerGray = 11; table = uint8(ones(numRow*textH,numBigCol*textW*(charPerGray+1))*255); %MMMMMM End Setting up optional arguments and default values MMMMMM [ISorted,IIndex]=sort(intensity(:)); if any(isnan(ISorted)), ISorted=ISorted(1:min(find(isnan(ISorted)))-1); IIndex=IIndex(1:length(ISorted)); end I=round(ISorted); if isempty(oldGLU), % Making new grayLookUp grayLookUp = cell(260,1); for t=1:256, [y,x] = ind2sub([numRow numBigCol],t); table = tableXYZ(table,x,y,1,t-1,charPerGray,textW,textH); list = find(I==t-1); grayLookUp{t} = cell(1,length(list)); for L=1:length(list), grayLookUp{t}{L} = data{IIndex(list(L))}{1}; numCharTotal = numCharTotal + 1; if showChar==1, show(grayLookUp{t}{L},1); pause(.5); end if L < charPerGray, table = tableXYZ(... table,x,y,L+1,255*grayLookUp{t}{L},charPerGray,textW,textH); end end end % End Making new grayLookUp else % append data into old grayLookUp database % checking textsize to be consistence oldTextWidthHeight = oldGLU{259}{1}; if oldTextWidthHeight ~= textWdHgt, error(sprintf('%s\n%s\n%s',... 'New character size is different from those in database.',... sprintf(' New text [width,height] = [%d,%d]',textW,textH),... sprintf('Database text [width,height] = [%d,%d]',... oldTextWidthHeight(1),oldTextWidthHeight(2)))); end % end checking textsize to be consistence grayLookUp = oldGLU; numNew = 0; countShow = 0; table=grayLookUp{258}{1}; for t=1:256, % going through all intensity values % coordinate for picture of chars arranged according to intensity [y,x] = ind2sub([numRow numBigCol],t); %disp(sprintf('%5d %5d',x,y)) list = find(I==t-1); oldLength = length(grayLookUp{t}); numCharTotal = numCharTotal+oldLength; numR = 0; % number of repeat for L=1:length(list), % going thru all chars which intensity=(t-1) % checking for repetition new = 1; for LL=1:oldLength, if grayLookUp{t}{LL}==data{IIndex(list(L))}{1}, new = 0; numR = numR+1; break end end % end checking for repetition if new==1, grayLookUp{t}{L+oldLength-numR} = data{IIndex(list(L))}{1}; numNew=numNew+1; if showChar==1, show(grayLookUp{t}{L+oldLength-numR},1); pause(0.1); end if (L+oldLength-numR) < charPerGray, table = tableXYZ(... table, x, y, ... L+oldLength-numR+1, ... 255*grayLookUp{t}{L+oldLength-numR}, ... charPerGray,textW,textH); countShow = countShow + 1; x1(countShow) = ... (x-1)*textW*(charPerGray+1)+(L+oldLength-numR)*textW+1; y1(countShow) = (y-1)*textH+1; %disp(sprintf(... % 'gray=%d, L+oldLength-numR=%d, x= %d, y= %d.',... % t-1,L+oldLength-numR,x1(countShow),y1(countShow))) end end % going thru all chars which intensity=(t-1) end % going through all intensity values end disp(sprintf('%d more characters added into database',numNew)); numCharTotal = numCharTotal + numNew; end % append data into old grayLookUp database % additional information about database grayLookUp{257}{1}=I; grayLookUp{257}{2}='I, sorted available intensity values'; grayLookUp{258}{1}=table; grayLookUp{258}{2}='table, picture of chars arranged according to intensity'; grayLookUp{259}{1}=textWdHgt; grayLookUp{259}{2}='textWidthHeight'; grayLookUp{260}{1}=numCharTotal; grayLookUp{260}{2}='numCharTotal'; % end additional information about database disp(sprintf('Total %d characters in database\n',numCharTotal)); show(table,10) %CCCCCC circle out all the new chars added in database CCCCCC eval('countShow;','countShow=0;') for cc = 1:countShow, % disp(sprintf('%d, x= %d, y= %d.',cc,x1(countShow),y1(countShow))) rectangle('position',... [x1(cc) y1(cc) 13 13],... 'curvature',[0 0],'EdgeColor','b'); end %CCCCCC End circle out all the new chars added in database CCCCCC % subfunction % to help composition of picture of chars arranged according to intensity function tableOut=tableXYZ(tableIn,x,y,z,value,zMax,textW,textH) % disp(sprintf('%d:%d,%d:%d = %d',... % (y-1)*13+1,y*13,(y-1)*130+(x+z-2)*13+1,(y-1)*130+(x+z-1)*13,value)); eval('textW; textH;','textW = 13; textH = 13;'); numCol = zMax+1; tableIn( (y-1)*textH+1 : y*textH , ... (x-1)*textW*numCol+(z-1)*textW+1 : (x-1)*textW*numCol+z*textW)... = value; tableOut=tableIn;