Code covered by the BSD License  

Highlights from
Hieroglyphs

image thumbnail
from Hieroglyphs by Ligong Han
Latin alphabet to Egyptian hieroglyphs Translator

cartouche(mpic,linewidth)
function cpic = cartouche(mpic,linewidth)
%CARTOUCHE   add cartouche to an image (matrix).
%   mpic is the matrix of the original image.
%   linewidth is the width of cartouche;
%   Horizontal direction: if linewidth < 0;
%   Vertical direction  : if linewidth > 0;
%
%   Phymhan Studio
%   10-Jul-2013 19:27:00

linecolor = uint8(255*reshape([0.25 0 0],[1,1,3]));
if nargin < 2
    linewidth = -8;
end
if iscell(mpic)
    mpic = mpic{1};
end
n = 8; %norm of the superellipse
[height width nclr] = size(mpic);
width_pad  = round(width *(1-cos(atan(height/width))^(2/n))/2);
height_pad = round(height*(1-sin(atan(height/width))^(2/n))/2);
a = width +2*width_pad;
b = height+2*height_pad;
mpic_pad = uint8(255*ones(b+(linewidth > 0)*abs(linewidth),...
    a+(linewidth < 0)*abs(linewidth),nclr));
mpic_pad((height_pad+1):(height_pad+height),...
    (width_pad+1):(width_pad+width),:) = mpic;
for x = 1:a
    for y = 1:b
        r = (abs(2*x/a-1)^n+abs(2*y/b-1)^n);
        if r >= 0.81 && r <= 1
            mpic_pad(y,x,:) = linecolor(1:nclr);
        end
    end
end
if linewidth < 0 %horizontal
    linewidth = abs(linewidth);
    K = linewidth/b;
    for y = 2:b-1
        for k = 1:nclr
            mpic_pad(y,((a+floor(abs(y-b/2)*K)):(a+linewidth)),k) ...
                = linecolor(k);
        end
    end
    %mpic_pad(:,(a+0):(a+abs(linewidth)),:) = 255*linecolor(1:nclr);
else %vertical
    linewidth = abs(linewidth);
    K = linewidth/a;
    for x = 2:a-1
        for k = 1:nclr
            mpic_pad(((b+floor(abs(x-a/2)*K)):(b+linewidth)),x,k) ...
                = linecolor(k);
        end
    end
    %mpic_pad((b+0):(b+abs(linewidth)),:,:) = 255*linecolor(1:nclr);
end
cpic = {mpic_pad};

end

Contact us