Untitled

mail@pastecode.io avatar
unknown
matlab
a year ago
2.9 kB
1
Indexable
Never
% Lista czcionek
fontsList = ["Arial", "Calibri", "Cambria", "Candara", "Century", "Constantia", "Corbel", "Courier New", "Georgia", "Lucida Sans Unicode", "Palatino Linotype", "Segoe UI", "Tahoma", "Times New Roman", "Trebuchet MS", "Verdana"];

% Lista liter
charsList = ["A", "Ą", "B", "C", "Ć", "D", "E", "Ę", "F", "G", "H", "I", "J", "K", "L", "Ł", "M", "N", "Ń", "O", "Ó", "P", "Q", "R", "S", "Ś", "T", "U", "V", "W", "X", "Y", "Z", "Ź", "Ż", "a", "ą", "b", "c", "ć", "d", "e", "ę", "f", "g", "h", "i", "j", "k", "l", "ł", "m", "n", "ń", "o", "ó", "p", "q", "r", "s", "ś", "t", "u", "v", "w", "x", "y", "z", "ź", "ż", ",", ".", "?", "!"];

% Tworzenie folderu "database"
if ~exist("database/", 'dir')
    mkdir("database/");
end

% Tworzenie folderów dla każdej litery
for i = 1:length(charsList)
    char = charsList(i);
    if char == ","
        folder_name = "przecinek/";
    elseif char == "."
        folder_name = "kropka/";
    elseif char == "?"
        folder_name = "zapytanie/";
    elseif char == "!"
        folder_name = "wykrzyknik/";
    elseif isstrprop(char, 'upper')
        folder_name = upper(char);
        folder_name = strcat(folder_name, '/');
    else
        folder_name = char;
        folder_name = strcat(folder_name, '_lower/');
    end
    if ~exist(strcat("database/",folder_name), 'dir')
       mkdir(strcat("database/",folder_name));
    end
end


% Tworzenie obrazów dla każdej litery i czcionki
for i = 1:length(charsList)
    char = charsList(i);
    if char == ","
        folder_name = "przecinek/";
    elseif char == "."
        folder_name = "kropka/";
    elseif char == "?"
        folder_name = "zapytanie/";
    elseif char == "!"
        folder_name = "wykrzyknik/";
    elseif isstrprop(char, 'upper')
        folder_name = upper(char);
        folder_name = strcat(folder_name, '/');
    else
        folder_name = char;
        folder_name = strcat(folder_name, '_lower/');
    end
    for j = 1:length(fontsList)
        %wygeneruj obraz z literą
        font = fontsList(j);
        image = insertText(255*ones(128,128),[16 16],char,'Font',font,'FontSize',64);
        imwrite(image, strcat("database/",folder_name, font, '.png'));

        %wygeneruj obraz z przechyloną literą
        im1 = insertText(255*ones(128,128),[16 16],char,'Font',font,'FontSize',64);
        im2 = imcomplement(im1);
        im3 = imrotate(im2, randi([-20, 20]), "nearest", "crop");
        r = -pi/18 + (pi/9)*rand(1);
        tform = affine2d([1, tan(r), 0; 0, 1, 0; 0, 0, 1]);
        im4 = imwarp(im3,tform);
        toCrop = (size(im4, 2) - 128) / 2;
        im5 = imcrop(im4, [0, toCrop, 128, 128]);
        im6 = imcomplement(im5);
        imwrite(im6, strcat("database/",folder_name, font + "_tilted", '.png'));
    end
end