Wiki

Reso-nance numérique | Arts et cultures libres

Outils du site


Panneau latéral

logiciels:linux:4.image
************************************
* Commandes pour le matériel vidéo *
************************************

Sommaire : matériel, ffmpeg, imagemagick, image ppm

---------
Serveur X
X11
X.org
---------

******************
*** Informations *
******************
lspci | pager
lsusb
modinfo
lsmod : modules chargés dans le noyau
lsof : tous les fichiers ouverts


**********************************
*** Connaître son matériel vidéo *
**********************************
dmesg | grep video
lsmod | grep video
grep video /etc/group


***********
*** Vracs *
***********
sudo aptitude install cheese camorama uvcvideo v4l2
sudo lsmod | more | grep video
sudo lsmod | more | grep usb
sudo lsmod | more | grep usbcore

sudo usermod -a -G video $USER && logout
sudo usermod -a -G video $USER && exit
 
hwinfo --help
hwinfo --sort sound
hwinfo --hw_item sound
man hwinfo
hwinfo --sound
hwinfo --camera

v4l-info
sudo v4l-conf
xdev
xawtv -hwscan

LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so cheese 
LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype


 1685  vlc v4l://dev/video0
 1686  vlc v4l://dev/video
 1687  vlc v4l://dev/v4l/video
 1688  vlc v4l://dev/v4l/video0
 1689  lsusb | grep -i logitech
 1690  lsmod | grep pwc
 1691  lsmod
 1692  lsmod | grep pwc
 1693  lsmod -h | grep pwc
 1694  lsmod -H | grep pwc
 1695  lsmod | grep pwc

 1767  setpwc
 1768  setpwc -x
 1769  setpwc -d /dev/video1
 1770  setpwc -x-d /dev/video1
 1771  setpwc -x -d /dev/video1
 1772  LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so cheese 
 1773  locate libpwc
 1774  locate pwc

 1749  cheese
 1750  gstreamer-properties 


 1745  sudo mknod /dev/video0 c 81 0
 1746  sudo chmod 666 /dev/video0
 1747  sudo ln -s /dev/video0 /dev/video


dov4l -h

*************************************
* Créer une vidéo à partir d'images *
*************************************
Source : http://urzhiata.emoc.org/creer-une-video-a-partir-d-images.html

Comment réunir une série d'images sous forme de vidéo? ffmpeg permet simplement, à partir d'une suite de fichiers images numérotés, de créer une séquence vidéo dans de nombreux formats. Voila la ligne de commande à utiliser :

pour fabriquer une vidéo au format flash FLV :

ffmpeg -r 25 -an -b 360k -i image-%04d.png -s 360x288 -f flv video.flv

-r 25 : définir le taux à 25 images/secondes
-an : desactiver l'audio
-b 360k : débit pour le flux vidéo, ici 360 kbits/secondes, à définir selon la taille du fichier que l'on souhaite
-i image-%04d.png : "modèle" pour les noms des fichiers image
-s 360x288 : définir les dimensions de la vidéo à obtenir
-f flv : fixer le format de sortie, ici flash vidéo FLV video.flv : nom du fichier vidéo à créer

Avec cette commande, les fichiers images doivent respecter un format bien précis et s'appeler image-0001.png, image-0002.png, etc. C'est ce qui est signifié par "%04d", bien sur on peut l'adapter (par exemple : %02d pour des fichiers de la forme image-02.png). La numérotation des fichiers image doit commencer à un et il ne peut pas y avoir de "trous". Parmi les formats d'image pris en charge par ffmpeg : jpg, tif, bmp, png, etc.

L'inverse est également possible : transformer une vidéo en série d'images

variante : modifier la durée d'affichage des images

Avec la commande précédente, chaque image est affichée pendant 1/25e de secondes. Pour modifier cette durée, il faut changer le nombre d'images par seconde de la vidéo source. Pour que chaque image reste visible une seconde, tout en conservant un taux de 25 images/seconde dans la vidéo finale on peut utiliser la commande suivante :

ffmpeg -r 1 -i image-%04d.png -an -b 360k -s 360x288 -r 25 -f flv video.flv

Pour qu'une image reste affichée 4 secondes, on utiliserait "-r 0.25", à l'inverse pour qu'une image reste un quart de seconde, il faudrait utiliser "-r 4". Cette modification concerne toutes les images de la vidéo, pour fixer séparément la durée d'affichage de chaque image, il faut utiliser ffmpeg avec avisynth

Comment renommer les fichiers par lot pour que leur nom ait le format souhaité (image_0001.jpg, image_0002.jpg) ?

Ant Renamer est un logiciel libre avec de nombreuses fonctions de renommage, en utilisant "énumération" on peut choisir le préfixe du fichier, le nombre de chiffres. Il dispose également de nombreuses autres fonctions de renommage! 


**********
* FFMPEG *
**********
ffmpeg -t 10 -f video4linux2 -s 320x240 -r 30 -i /dev/video0 -f oss -i /dev/dsp1 -f mp4 webcam.mp4
ffmpeg -f x11grab -r 15 -s 400x400 -i :0.0 -vcodec mjpeg screen_grab.mov 
ffmpeg -isync -t 10  -f x11grab -r 15 -s 400x400 -i :0.0 -vcodec mjpeg screen_grab.mov 

Avec xwininfo 
ffmpeg -isync -t 10  -f x11grab -r 15 -s 350x430 -i :0.0+30,39 -vcodec mjpeg screen_grab.mov

****************
* IMAGE MAGICK *  
****************
convert -background lightblue -fill blue  -font Palatino-Bold  -size 165x70  -pointsize 24  -gravity center label:"Pure Data" label_gravity.gif     

ImageMagic

Imagemagick est un visualisateur et un programme puissant de conversion/édition d'images qui s'utilise en ligne de commande. Le site officiel est: www.imagemagick.org.

Installation sous Debian avec aptitude:

 # aptitude install imagemagick

convert

Convert est une commande de la suite ImageMagic, qui permet de redimmensionner ou de convertir en une seule fois toutes les images ou phots d'un répertoire. On peut aussi créer des animations. Pour commencer il faut ce placer avec la commande cd dans le répertoire contenant les images à travailler:

 $ cd MonDossier

Convertir une image .jpg en .png:

 $ convert image.jpg image.png

Convertir et redimmensionner une image de moitié:

 $ convert image.jpg -resize 50% image.png

Faire une rotation de l'image:

 $ convert -rotate 90 image.jpg image2.jpg

Pour créer un film .mpg, le délay est de 15 sur 100, le 0 signifie infini, le * signifie toutes les images au format jpg et le fichier créé se nommera anim.mpg:

 $ convert -delay 15 -loop 0 *.jpg anim.mpg

Pour créer un .gif animé, le délay est de 10 sur 100:

 $ convert -delay 10 -loop 0 *.jpg anim.gif

montage

Créer une image aperçu, d'un dossier avec des miniatures:

 $ montage -background black  dossier/*.png montage.png


***************
* Imagemagick *
***************
ImageMagick est un logiciel en ligne de commande très puissant de manipulation d'images dans pratiquement tous les formats existants. Il consiste en une suite d'outils permettant par exemple de changer le format, l'échelle, l'orientation, rajouter une bordure ou du texte, appliquer un filtre, fusionner plusieurs image, animer une suite d'images, etc. Il est possible d'utiliser ces différents outils dans des programmes écrits en C, C++, ruby, python, perl, etc.
Installation

Il vous suffit, pour cela, d'installer imagemagick. .
Les différents outils

Les outils formant ImageMagick possèdent de nombreuses options étendant très loin leurs possibilités. La plupart de ces options sont communes à plusieurs outils. Ainsi, l'option -resize 50% permet de visualiser une image à la moitié de sa taille avec display et de créer une image de taille moitié avec convert.

Lors de vos tests si vous êtes sous gnome et que vous souhaitez un moyen simple de visualiser le résultat de la dernière commande, pensez à utiliser eye of gnome:

eog monimage.png

Voici la liste des différents outils ainsi que quelques exemples simples, le cas échéant.
Display

Display affiche une image à l'écran :

display image.png

En cliquant sur l'image apparue à l'écran, vous aurez accès à une interface graphique sommaire qui vous permettra tout de même de nombreuses modifications de l'image. utilisez la touche 'q' pour quitter l'application.
Convert

Convert permet la modification d'une ou plusieurs images, par exemple :

    *
      pour créer une image tga à partir d'une image jpg :
	
convert image.jpg image.tga

    *
      pour créer un fichier gif animé à partir de plusieurs images png :

convert images_*.png anime.gif

    *
      pour créer un document pdf à partir d'une série d'images png :

convert images_*.png document.pdf

Acrobat Reader rapporte une erreur 14 à l'ouverture d'un document pdf composé à partir d'images au format png. le problème ne se pose pas si l'on convertit d'abord les images au format jpg par exemple.

    *
      pour diminuer la taille d'une image tout en effectuant une rotation de 90° dans le sens horaire :

convert images.jpg -resize 50% -rotate 90 image.jpg

    *
      pour tourner les images en fonction de leur orientation donnée dans le format Exif, comme par exemple les images issues d'un appareil photo numérique. L'image n'est retournée que si elle a été prise en portrait, si elle a été prise en paysage, celle-ci n'est pas modifiée :

convert image.jpg -auto-orient image_retournee.jpg

    *
      pour ajouter un copyright ("© Ubuntu" par ex.) ou watermark sur les photos, des scripts ont déjà été faits, facilitant l'utilisation des lignes de commandes, en particulier pour l'ajout d'un copyright image transparente: voir dans ce post de forum avec ce script de Fake.

Mogrify

Mogrify est utilisé pour apporter la même modification à plusieurs images. par exemple, pour augmenter le contraste d'une série de photos :

mogrify -sigmoidal-contrast 5,50% webcam-shot*.png

Il est également possible d'utiliser mogrify pour redimensionner une image (ou un lot d'images), avec la commande suivante :

mogrify -resize 800x600 image.jpg

ou pour toutes les images d'un dossier :

mogrify -resize 800x600 *.jpg

Attention, mogrify réécrit sur les images d'origine, pensez à faire des tests avant de lancer la commande finale ou utiliser l'option -path pour que le résultat de la ligne de commande s'écrive dans un autre répertoire:

mogrify -resize 800x600 -path autre_repertoire *.jpg

Identify

Identify donne des informations sur l'image.

    *
      Pour des informations sommaires :

identify image.jpg

    *
      Pour des informations complètes :

identify -verbose image.jpg

    *
      Pour les images contenant un grand nombre de couleurs, la commande précédente pourra renvoyer des centaines de lignes d'informations. Pensez à l'associer à la commande less ou grep à travers un pipe pour plus de lisibilité. Pour connaître la qualité de votre jpg :

identify -verbose image.jpg | grep Quality

Import : Pour faire des captures d'écran
Capture d'écran interactive :

Utilisez la commande

import ma_capture.png

Le curseur de la souris se transformera alors en « croix ».

Vous pourrez alors :

    *
      cliquer une fois dans l'écran pour capturer tout l'écran.
    *
      tracer un cadre avec un « cliquer-glisser » qui capturera la zone définie.

Principales options :

-window Cette option vous permet de capturer l'écran entier:

import -window root image.png

-pause Cette option vous permet d'attendre le nombre spécifié de secondes avant que le curseur ne change de forme.

import -pause 10 image.png

-crop Utilisable en conjonction avec -window, cette option vous permet de spécifier exactement quelle zone de l'écran doit être capturée.

import -window root -crop 800x600 image.png  # permet de sélectionner une zone de 800x600 pixels en partant du coin supérieur gauche de l'écran
import -window root -crop 800x600+150+100 image.png  # permet de sélectionner une zone de 800x600 pixels en partant du point situé 150 pixels à plus à droite et 100 pixels plus bas que le coin supérieur gauche de l'écran

Animate

Animate permet la visualisation d'animations.

    *
      Pour visionner un gif animé :

animate images.gif 

    *
      Pour animer une série de photos à raison d'une par seconde :

animate -delay 100 *.png 

Compare

Compare crée, à partir de 2 images, une troisième qui représente la différence entre les 2 premières. Utile pour savoir où ont été opérées des modifications :

compare imageA.png imageB.png difference.png

Composite

Pour se faire chevaucher et mélanger des images.
Conjure

Interprète et exécute un script écrit en Magick Scripting Language (MSL).
Montage

Pour faire une composition de plusieurs images.

L'option '-geometry' donne la taille de chaque image en pixels qu'il faudra introduire. S'utilise comme suit : -geometry "largeur"x"hauteur". L'option '-tile' donne la disposition des images sur la grande unifiée : -tile "colonnes"x"lignes". En pratique :

montage -geometry "largeur"x"hauteur" -tile 2x2 *.jpg together.jpg

donnera autant d'images qu'il le faut pour assembler tous les jpeg du dossier courant à raison de quatre par page dans des jpeg dont le nom commence par together (together-0.jpg, together-1.jpg, etc.).

Très utile pour imprimer des photos en format carte sans gaspiller de papier… mais il faut découper après (utilisation d'une guillotine recommandée).
Stream

Pour pouvoir manipuler de grandes images.
Liens

    *
      site officiel (en)
    *
      De nombreux exemples(en)
    *
      Documentation non-officielle en français

Contributeurs : kanor, ZondeR


*****************************
Video to GIF, Optimization Summary
A software developer who uses IM to create Movie GIFs, Benoit Rouleau, in discussion with me, gave me a AVI video of a plane flying over, to help us mutually explore IM video conversion techniques.

However while the AVI itself is quite small, the uncompressed video is a massive [IM Text] bytes in size, and involves [IM Text] colors, over [IM Text] frames.

IM however has no real trouble converting this video into a GIF animation. However be warned that you will probably get some unsupported 'AVI chunk' errors, which can be ignored by using a "-quiet" control setting.


  convert -quiet -delay 1 plane.avi plane.gif

	[IM Output]

This used ImageMagick's the default Color Quantization and Dithering methods, to produce a very reasonable conversion of the video. Very few color problems exist, because the video uses very few colors to start with. This is not always the case, especially as GIF has 256 colors per frame limit.

However the animation file is [IM Text] bytes in size, which while only 1/5th the size, due to color reduction and GIF pixel data compression, it is still rather large.

Also if you study the resulting animation further you will find that of the [IM Text] frames in the image, [IM Text] frames had their own own separate local color table added. That is each and every frame in the GIF animation required there own color index table. That is while each frame has less that 256 colors (due to the GIF format limitations), the whole animation is using a total of [IM Text] colors.

Unfortunately the GIF format does not compress color tables, so all those extra color tables could be using up to:   256 colors * 3 byte per color * 106 frames;   or 81,408 bytes of file space. Not a lot for a 1Gbyte video but still an appreciable amount of space, especially as we optimize the video further.

Added to this is that the animation will not GIF frame optimize very well. Not only because the background is moving (due to the camera panning upward), but also because IM used a Error Correction Dither (Hilbert Curve Dither), which produces a pseudo-random pattern of colors that is different from frame to frame. A later example will make this 'dither noise' much more visible.

Common Global Color Table
Here I Generate a Single Global Color Table for all the frames of the video.


  convert -quiet -delay 1 plane.avi  +map   plane_cgc.gif

This naturally results in [IM Text] local color tables, and a file size of [IM Text] bytes. 	[IM Output]

As you can see the resulting animation has no extra local colortables. Instead IM generated a single global color table of [IM Text] of the 'best' colors based on all the frames in the animation.

Unfortunately this also resulted in the pixel data not compressing as well as it did before, as a stronger dither was required. The result is a slightly worse looking animation, that is roughly the same size as the previous.

For this specific video of limited colors, I could even reduce the number of colors used even further say to only 64 colors without too many problems, producing an even smaller animation file size. This however is very dependent on the video sequence used, and may not look very good.

Your own video may have a better result or worse result, especially when dealing with a video that uses a lot more colors and possibly multiple scenes.

Universal Global Color Table
The better way to generate a 'smaller' GIF animation is to just supply a general universal range of colors rather than generate the 'best' global color table for an animation. Use one that should work well regardless of what colors are present in the original video.

Another reason for doing this is that you can make you video longer without serious detrimental effects on the color selection, or resorting local color tables for each frame. Each frame is dithered to the same color map, completely independently of what other frames are in the animation.

Here I use a '332' color map which is usually regarded as being a very good standard colormap when no transparency is needed. I have often seen this colormap (or a 219 color 'web-safe' colormap) used often in various video formats.


  convert -quiet -delay 1 plane.avi -map colormap_332.png plane_ugc.gif

	[IM Output]

This animation has [IM Text] local color tables, and as a result the animation is smaller or [IM Text] bytes in size.

The problem however is that you will often see a obvious and annoying 'noise' in areas of constant color. This noise was also present in ALL the previous video animations. It is only now visible due to the use of a more universal, and thus more widely spread out color mapping.

The noise is actually caused by the dithering of the reduced color set when regenerating the image. However, this produces a pseudo-random pattern of colors that changes from frame to frame, resulting in the appearance of background noise in the image. See Problems with E-Dithers for more detail as to why this happens.

We could just turn off the color dithering to remove the 'dither noise'...


  convert -quiet -delay 1 plane.avi \
          +dither -map colormap_332.png plane_ugc_nd.gif

Which has [IM Text] local color tables, and is [IM Text] bytes in size. 	[IM Output]

The resulting animation is a very small 1/60th the size of the original animation, generally because of the large expanses of solid color producing extremely good pixel compression. But while it fixes the dither noise, and make for a very small file size, you get color banding instead, which is generally regarded as a very bad trade-off.

Ordered Dithered Video
The real solution is to use a different color dithering technique, which does not produce a different pattern from one frame to the next.

For example here I used a Ordered Dither using Posterized Color Levels to dither the same universal '332' colormap.


  convert -quiet -delay 1 plane.avi \
          -ordered-dither o8x8,8,8,4 +map plane_od.gif

Which has [IM Text] local color tables, and is [IM Text] bytes in size. 	[IM Output]

The above also used the "+map" operator, to ensure that all the images use the exact same global color map (which the ordered dither already reduced to a maximum of 256 colors). As the number of colors is already optimal, the "+map" operator does no dithering, or color reduction.

The resulting dither pattern is not random, and does not change greatly from one frame to the next. Thus the 'dither noise' has been remove from the animation resulting in a fixed color pattern from from to frame.

The pattern is also very repetitive allowing much better compression.

And finally as the color map is fixed, it should work reasonably well regardless of what video is used.

Higher Quality Ordered Dithered Video
This specific video however only uses a small range of colors, mostly various shades of blue, so it doesn't actually use a lot of the colors provided by a general uniform colormap.

In fact only [IM Text] colors were used in the last video animation!

This is extremely low, and as such also quite visible. But it also means that this particular animation can benefit from using a large number of 'color levels' in the ordered dither operation, so as improve the overall quality.

First however we need to determine how many color levels the animation can handle before it reaches the 256 color limit imposed by both the GIF file format and the global colormap re-mapping.

The tricky part however is that you must determine these BEFORE you save the animation to the limited GIF format. And here is the command I use...


    convert -quiet plane.avi -ordered-dither o8x8,23 -append -format %k info:

[IM Text]

Basically I increased and decreased the number of color levels to use, until I had a figure that was just within the required 256 color limit.

I can then apply the discovered 'color level' choice to the plane animation.


  convert -quiet -delay 1 plane.avi \
          -ordered-dither o8x8,23 +map plane_od2.gif

Which has [IM Text] local color tables, is [IM Text] bytes in size, and [IM Text] colors. 	[IM Output]

Actually the two commands could have been merged together, but I will leave that as an exercise to you. Hint, use "-write" with parenthesis, or "-identify".

As you can see a very high quality, ordered dithered video was generated, which is on a par with the 'best colormap' global color map version we generated earlier, but also 1/3 smaller in size, and does not contain any hard to see 'dither noise'.

Of course as the quality is so much higher, it does require a larger file size, as it doesn't compress as well as the lower quality version.

On the other hand you now actually have a good control over the quality vs file size trade-off in the form of the number of 'color levels' used.

Just remember this technique is a special case, for an animation that does not use too many colors. And making the video longer by adding more frames will also add more colors, and thus require a reduction in the 'color level' quality control.

This is about the best method of color optimization I have yet seen for general GIF animations. It removes 'dither noise', provides some quality control, and retains the ability to use other GIF animation optimization methods, such as Frame Optimization.

Compression (Transparency) Optimization
Because this video uses a panning camera, the background of the video changes from frame to frame. This means the GIF animation will not Frame Optimize very well.

However we can still use a simple Transparency Optimization to further reduce the final size of the GIF animation.


  convert plane_od2.gif  -layers OptimizeTransparency +map plane_opt.gif

Which has [IM Text] local color tables, is [IM Text] bytes in size, and [IM Text] colors. 	[IM Output]

That is one extra color, a transparent color index, was added to the image, and any pixel that does not change the currently displayed color was made transparent. This in turn generates large segments of transparent areas in the original animation, as well as repeats of similar pixel sequences, which generates a improved LZW compression in the final GIF image.

Not bad, the animation is now half that of the direct conversion to GIF, and still a reasonably high quality.


If you like to add to the above, discuss the techniques to further improve them, please contact me, or the IM forum. I am more than happy to hear about your views, techniques and discussions, or look at a specific video/animation problem you may have.

De-Interlacing a video frame
Not all images are from digital cameras. It is very common to extract images from a digital video feed from a non-CCD video camera. These images are interlaced for direct display on a TV, resulting in every second line being a different frame of the image (interlacing).

For two frames where things aren't moving, the interlacing is usually not very noticeable. Perhaps producing only a slight edge blurring of the image. But when a fast moving object is involved, the resulting interlaced image is very disconcerting, as two frames have been merged together.

Wolfgang Hugemann <Auto@Hugemann.de> (Germany), had this problem and sent me a snapshot of a crash test, that Wolfgang took himself. But for demonstration I will use a smaller image cropped from this one. The techniques however will work on the full sized image.


    convert video_frame.png  -crop 100x100+200+470 +repage  interlaced.png

	[IM Output]

	Wolfgang Hugemann used a TIFF format for the original video frame, I converted this to PNG for use on IM Examples. Do NOT be tempted to use JPEG for these images, until you have finished processing as it will destroy the low level quality needed for this process.

As you can see the interlacing shows two separate frames, as it comes from a interlaced PAL digital video sequence, (approx 50 half frames per second). Yes the car was moving very fast and the camera is using a high speed shutter, producing a very high quality video image. The resulting image is two interwoven half-frames with the car's side mirror moving quite a distance during the intervening 1/50 second time period between half frames.

Here we just replace one of the interlaced half-frames (every second line) with white. This is the standard de-interlacing method, known as a 'BoB' filter. This was contributed by Wolfgang for IM Examples.


  convert interlaced.png  -fx "floor(j/2)==j/2 ? u : 1"  deinterlace_1.png

	[IM Output]

Now the FX operator is slow, so an alturnative is to create a 'striped image'. Such an image can be generated from the special "pattern:Horizontal2" built-in image.

That image can then be overlaid with the original, using a 'Screen' composition method to overlay white lines, or use 'Multiply' or overlay black lines. For example...


  convert -size 100x100 pattern:Horizontal2 \
          interlaced.png -compose Multiply -composite  deinterlace_2.png

	[IM Output]

Negating the pattern can be used to select the other half of the interlaced image. Or if you change the 'Multiply' to 'Screen' you can extract frames with a white background.

As an alternative I tried to fill in the missing frame lines by just duplicating the previous line.


    convert interlaced.png  -fx "u.p{i,j-j%2}"  deinterlace_3.png

	[IM Output]

You can also use a 'pixelization' technique to shrink and expand an image so as to double up every second line.


    convert interlaced.png -sample 100%x50% \
                           -sample 100%x200%  deinterlace_4.png

	[IM Output]

And with a slight variation you can combine the lines on both sides to vertically smooth the half-frame image as part of the resize expansion.


    convert interlaced.png -sample 100%x50% \
                           -resize 100%x200%  deinterlace_5.png

	[IM Output]

The result is a particularly nice extraction of the second half-frame from the video (time-wise).

If you want to extract the second half-frame of the image you only need to "-roll" the image by one pixel before de-interlacing.


    convert interlaced.png -roll +0+1 -sample 100%x50% \
                                      -resize 100%x200%    deinterlace_6.png

	[IM Output]

*************
* Image PPM *
*************
Il existe deux catégories d'images PPM :
. un format ASCII : « ASCII » écriture directe dans un bloc-notes possible
. un format binaire : « RAW » écriture à l'aide d'un éditeur hexadécimal



exemple au format ASCII
en-tête du Fichier
signature du fichier
Pour les formats ASCII :
P1 = PBM bitmap
P2 = PGM greymap
P3 = PPM pixmap

Pour les formats Binaires :
P4 = PBM raw bitmap
P5 = PGM raw greymap
P6 = PPM raw pixmap
P3
 
un séparateur = espace, Tab, LF ou CR
[espace]
en-tête de l'image
largeur de l’image en caractère ASCII
5
 
un séparateur
[espace]
 
hauteur de l’image en caractère ASCII
2
 
un séparateur
[espace]
Corps
valeur maximum des couleurs
14
 
codage de chaque pixel ligne par ligne, en partant du coin haut-gauche
PPM ASCII :
Les valeurs RVB des pixels en ASCII séparées par un
séparateur (espace)
PPM raw :
si N-1 < 256 chaque valeur est codée sur 1
octet
si N-1 ? 256 chaque valeur est codée sur 2
octets
l’octet le plus significatif est le 1er (Big Endian)
0 0 14 2 0 14 4 0 14 6 0 14 8 0 14 10 0 14
0 0 14 2 0 1 4 0 14 6 0 14 8 0 14 10 0 14 0

- Exemple d'une image PPM en codage ASCII (à recopier simplement dans un bloc-notes avec l'extension .ppm):
P3 6 2 14 0 0 14 2 0 14 4 0 14 6 0 14 8 0 14 10 0 14 0 0 14 2 0 14 4 0 14 6 0 14 8 0 14 10 0 14 0
/home/resonancg/www/wiki/data/pages/logiciels/linux/4.image.txt · Dernière modification: 2015/03/08 00:12 de resonance