You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
5.1 KiB
169 lines
5.1 KiB
\chapter{Image} |
|
\label{chap:image} |
|
|
|
Le traitement des images est un art à part entière. Nous allons |
|
voir quelques grands classiques de la catégorie pas du tout |
|
interactif. Le genre de machin que l'on peut ranger au fond |
|
d'un script shell pour le réutiliser la semaine prochaine. |
|
|
|
% ------------------------------------------------------------------- |
|
|
|
\section{ImageMagick}\index{ImageMagick} |
|
|
|
Attention, ça va devenir \textsl{hardu}% |
|
\footnote{Nous attendons tous avec impatience l'ouvrage magistral |
|
de maitre Brunus}, |
|
l'abondance d'options des outils ImageMagick est vraiment énorme, |
|
et leurs interactions parfois troublantes\dots |
|
|
|
Il y a plusieurs binaires dans le paquet : \texttt{convert} pour |
|
la plupart des traitements, |
|
\texttt{display} et \texttt{animate} pour visualiser des images, |
|
\texttt{identify} pour en lire les méta-données. |
|
|
|
\subsection{L'option \texttt{-geometry}} |
|
|
|
C'est une notion importante, car elle est utilisée comme paramètre |
|
par beaucoup d'options. C'est avec ça que l'on peut définir des |
|
choses comme la taille (largeur et hauteur) d'une image, ou |
|
la position d'un texte dans l'image, ou une zone sur laquelle |
|
on va travailler. |
|
|
|
\subsection{Écrire du texte} |
|
|
|
Voici un exemple concret |
|
(tiré du script d'encodage du \textsc{cloître}\index{cloître}) |
|
qui montre l'essentiel pour bien débuter. C'est une fonction |
|
écrite en bash\index{bash} qui rajoute un texte sur une image~: |
|
|
|
\lstinputlisting[language=sh]{code/tagpic.sh} |
|
|
|
Quelques explications semblent nécessaires, parce que certaines |
|
options sont un peu ésotériques et parfois inter-dépendantes\dots |
|
|
|
\begin{itemize} |
|
\item{txtfont} |
|
\item{fontsize} |
|
\item{kerning} |
|
\item{colors} |
|
\item{txtopts} |
|
\item{gravity} |
|
\item{annotate} |
|
\end{itemize} |
|
|
|
Question : comment mettre une couleur de fond à ce texte ? |
|
|
|
\subsection{montage} |
|
|
|
Krkrkr |
|
|
|
\subsection{Faire des GIFs animées}\index{GIF} |
|
|
|
Ces petites images clignotantes sont l'essence même du |
|
Web\index{web} moderne depuis 1992 malgré leurs limitations, |
|
et \texttt{convert} sait très bien les générer. |
|
|
|
\begin{verbatim} |
|
convert -delay 20 -loop 0 a.png b.png c.png foo.gif |
|
\end{verbatim} |
|
|
|
Ce sujet pertinent est abordé plus en détails en |
|
page \pageref{chap:gif89a} |
|
|
|
\subsection{Extraire une partie de l'image} |
|
|
|
Dans cette fonctionnalité aussi, il semble y avoir quelques |
|
subtilités. |
|
|
|
\begin{verbatim} |
|
DIMENSION="1024x768" |
|
POSITION="+R12+0" |
|
convert -crop ${DIMENSION}${POSITION} +repage $img $dst |
|
\end{verbatim} |
|
|
|
\textsl{Use +repage to completely remove/reset the virtual canvas |
|
meta-data from the images.} |
|
En gros, on en a besoin quand une opération va |
|
changer la dimension de l'image. |
|
|
|
\subsection{Ressources} |
|
|
|
Le futur livre de Brunus. Réclamez les prmiers drafts dans |
|
l'IRC\index{IRC} \texttt{freenode\#paulla} \textit{:)} |
|
|
|
\texttt{http://www.fmwconcepts.com/imagemagick/index.php} |
|
|
|
% ------------------------------------------------------------------- |
|
|
|
\section{Gmic}\index{Gmic} |
|
|
|
\textsl{Perform generic image processing operations, through the G'MIC |
|
language interpreter. gmic: GREYC's Magic for Image Computing.} |
|
|
|
\index{XXX} |
|
|
|
Existe aussi en plugin pour Gimp\index{Gimp} avec une interface |
|
pleine de curseurs et de boutons. |
|
|
|
% ------------------------------------------------------------------- |
|
|
|
\section{NetPBM}\index{netpbm}\label{netpbm} |
|
|
|
With the Netpbm file formats, it’s trivial to output pixels using |
|
nothing but text based IO% |
|
\footnote{https://www.vidarholen.net/contents/blog/?p=904}. |
|
|
|
\begin{verbatim} |
|
#!/bin/bash |
|
exec > my_image.ppm # All echo statements will write here |
|
echo "P3 250 250 255" # magic, width, height, max component value |
|
for ((y=0; y<250; y++)) { |
|
for ((x=0; x<250; x++)) { |
|
echo "$((x^y)) $((x^y)) $((x|y))" # r, g, b |
|
} |
|
} |
|
\end{verbatim} |
|
|
|
\subsection{Questions} |
|
|
|
Comment faire un \textsl{resize} avec NetPBM ? |
|
Est-il nécessaire d'apprendre la bibliothèque de fonctions |
|
\texttt{libnetpbm} ? |
|
|
|
% ------------------------------------------------------------------- |
|
|
|
\section{Portable Network Graphic}\index{PNG} |
|
|
|
Voici le problème du soir% |
|
\footnote{\textsl{trollday} Fri Nov 13 00:07:19 CET 2020} : |
|
j'utilise pour lire ce format de fichier la bibliothèque |
|
\texttt{pnglite} qui a de gros soucis avec beaucoup de |
|
ceux-ci, par exemple ceux qui sont en \texttt{sRGB} crées |
|
par des outils essentiels comme POVray\index{POVray}. |
|
Il serait bon de voir la \texttt{libpng} officielle. |
|
|
|
pngcrush ? optipng ? |
|
|
|
\texttt{pngtopnm \$png | pnmtopng > \$goodpng} |
|
|
|
% ------------------------------------------------------------------- |
|
|
|
\section{Tag Image File Format} \index{TIFF} \label{TIFF} |
|
|
|
\begin{quote} |
|
Yes, but tiffcp is by far the most significant case. And perhaps one of the |
|
most used of the tools. I may not be impartial on this, though :-) because I |
|
use it heavily. |
|
\end{quote} |
|
|
|
\begin{verbatim} |
|
tiffcp combines one or more files created according to the Tag Image |
|
File Format, Revision 6.0 into a single TIFF file. Because the output |
|
file may be compressed using a different algorithm than the input |
|
files, tiffcp is most often used to convert between different compres‐ |
|
sion schemes. |
|
\end{verbatim} |
|
|
|
|
|
|
|
% -------------------------------------------------------------------
|
|
|