issue114:inkscape
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue114:inkscape [2016/11/04 08:49] – d52fr | issue114:inkscape [2016/11/09 15:43] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 3: | Ligne 3: | ||
Let's look at how a convolution matrix actually works by picturing its effect on a simple image made up of a small set of pixels. For this demonstration, | Let's look at how a convolution matrix actually works by picturing its effect on a simple image made up of a small set of pixels. For this demonstration, | ||
- | Ce mois-ci, nous allons | + | Ce mois-ci, nous allons |
- | Regardons comment fonctionne | + | Regardons comment fonctionne une matrice de convolution en illustrant son effet sur une image simple faite d'un petit ensemble de pixels. Pour cette démonstration, |
**Our first matrix will be a 3×3 array, with each cell containing the number 1.00, and the “target” specified as the center cell of the matrix. Here's how that looks in the Inkscape GUI: | **Our first matrix will be a 3×3 array, with each cell containing the number 1.00, and the “target” specified as the center cell of the matrix. Here's how that looks in the Inkscape GUI: | ||
Ligne 18: | Ligne 18: | ||
Notre première matrice sera un tableau 3x3, avec le nombre 1.00 dans chaque case, et la « cible » spécifiée comme étant la cellule centrale de la matrice. Voici à quoi ça ressemble dans l' | Notre première matrice sera un tableau 3x3, avec le nombre 1.00 dans chaque case, et la « cible » spécifiée comme étant la cellule centrale de la matrice. Voici à quoi ça ressemble dans l' | ||
- | Le procdé | + | Le procédé |
La valeur du pixel de sortie est donc : | La valeur du pixel de sortie est donc : | ||
Ligne 32: | Ligne 32: | ||
Some of you may have noticed that I've conveniently started with a pixel that is not on the very edge of the filter area. How does Inkscape calculate the value for the top-left pixel, for example, given that five of the points covered by the matrix simply don't exist? The answer lies in the Edge Mode popup in the filter settings: “Duplicate” copies the pixels from the outer edge to fill any missing values; “Wrap” uses the pixels from the opposite side of the image to fill the gaps as though it were working on a tiled version of the input; “None” just sets the channel values for the missing pixels to zero.** | Some of you may have noticed that I've conveniently started with a pixel that is not on the very edge of the filter area. How does Inkscape calculate the value for the top-left pixel, for example, given that five of the points covered by the matrix simply don't exist? The answer lies in the Edge Mode popup in the filter settings: “Duplicate” copies the pixels from the outer edge to fill any missing values; “Wrap” uses the pixels from the opposite side of the image to fill the gaps as though it were working on a tiled version of the input; “None” just sets the channel values for the missing pixels to zero.** | ||
+ | |||
+ | Pas besoin de grandes connaissances mathématiques pour comprendre que les cinq pixels blancs ont apporté une valeur de 255 à la sortie, alors que les pixels noirs ne contribuent en rien. Aussi, la valeur utilisée pour le pixel de sortie est simplement 255 x 5 = 1 275. Sauf que les valeurs de sortie sont limitées, de sorte que la vraie valeur de sortie est 255 seulement, cette matrice change le pixel noir en un pixel blanc. | ||
+ | |||
+ | Sur le pixel suivant, le résultat est identique. Cette fois-ci, seulement trois pixels blancs contribuent à la sortie ; mais la valeur est encore de 765, qui est bornée, et donc la sortie est à nouveau blanche. | ||
+ | |||
+ | En considérant les pixels noirs restants dans notre image, il paraît assez évident que tous ceux de l' | ||
+ | |||
+ | Certains d' | ||
**Or at least that's how it's supposed to work. According to the official Inkscape manual, this parameter is completely ignored by Inkscape, despite being present in the UI. It doesn' | **Or at least that's how it's supposed to work. According to the official Inkscape manual, this parameter is completely ignored by Inkscape, despite being present in the UI. It doesn' | ||
Ligne 38: | Ligne 46: | ||
Now each output pixel is the average of nine pixels from the input image. Although it might not be clear from this small example, the outcome is a simple blurring of the input image. In reality, it would be better to use a Gaussian Blur primitive if you just want to soften your image a bit, but this was, of course, just a demonstration of the mathematics that takes place behind the scenes with the Convolve Matrix.** | Now each output pixel is the average of nine pixels from the input image. Although it might not be clear from this small example, the outcome is a simple blurring of the input image. In reality, it would be better to use a Gaussian Blur primitive if you just want to soften your image a bit, but this was, of course, just a demonstration of the mathematics that takes place behind the scenes with the Convolve Matrix.** | ||
+ | |||
+ | Ou, du moins, c'est ainsi que c'est censé fonctionner. D' | ||
+ | |||
+ | Parce que les valeurs que nous avons choisies entraînent une troncature des résultats de calcul, notre filtre, tel qu'il est, crée simplement en sortie des pixels noirs et blancs. Avant la troncature, les résultats étaient 1 275 et 765, mais notre action suivante supprime toute différence de valeur parce qu'ils sont tous au-dessus de 255. En utilisant le contrôle Diviseur dans les paramètres du filtre, nous pouvons adapter la sortie des calculs avant troncature, nous permettant de restreindre les valeurs pour préserver ces différences. Une bonne règle empirique est de mettre le diviseur à la même valeur que la somme de chacun des nombres de la matrice. En le réglant à 9 dans notre exemple, les sorties 1 275 et 765 sont réduites à 142 (1 275 ÷ 9) et 85 (765 ÷ 9), nous donnant ce résultat : | ||
+ | |||
+ | Ici, chaque pixel de sortie est la moyenne de neuf pixels de l' | ||
**Now let's move on to some more interesting matrices. I'm going to stop with the pixel-by-pixel approach, and the mathematical explanations – it's all just an extension of the examples I've shown so far, but with larger images and multiple color channels. We'll use a different classical image to demonstrate these because Mona, quite honestly, isn't that interesting when you apply a convolution matrix. So we'll switch to Michelangelo' | **Now let's move on to some more interesting matrices. I'm going to stop with the pixel-by-pixel approach, and the mathematical explanations – it's all just an extension of the examples I've shown so far, but with larger images and multiple color channels. We'll use a different classical image to demonstrate these because Mona, quite honestly, isn't that interesting when you apply a convolution matrix. So we'll switch to Michelangelo' | ||
A Sobel operator emphasises the differences between adjacent pixels in one direction or another. The result is essentially a map with bright colors where there is a sharp transition between pixels, and dark colors where there is little or no difference between adjacent pixels. In practical terms, therefore, it acts as an edge detection filter, in this case highlighting vertical edges (note, particularly, | A Sobel operator emphasises the differences between adjacent pixels in one direction or another. The result is essentially a map with bright colors where there is a sharp transition between pixels, and dark colors where there is little or no difference between adjacent pixels. In practical terms, therefore, it acts as an edge detection filter, in this case highlighting vertical edges (note, particularly, | ||
+ | |||
+ | Maintenant, passons à des matrices plus intéressantes. J' | ||
+ | |||
+ | Un opérateur Sobel amplifie les différences entre les pixels voisins dans une direction ou une autre. Le résultat est essentiellement une configuration avec des couleurs lumineuses, où la transition entre pixels est franche, et des couleurs sombres où il y a peu ou pas de différences entre les pixels adjacents. Par conséquent, | ||
+ | |||
**Rotating the values of the matrix through 90° (so that the top row contains 1, 2, 1 and the bottom row is -1, -2, -1) turns it into an edge detection filter for horizontal edges. In this case the coving vanishes, but any near-horizontal shapes are accentuated: | **Rotating the values of the matrix through 90° (so that the top row contains 1, 2, 1 and the bottom row is -1, -2, -1) turns it into an edge detection filter for horizontal edges. In this case the coving vanishes, but any near-horizontal shapes are accentuated: | ||
+ | |||
A more general form of edge detection, which highlights both vertical and horizontal lines resulting in an “outline” version of the original image, can be achieved with the following matrix: | A more general form of edge detection, which highlights both vertical and horizontal lines resulting in an “outline” version of the original image, can be achieved with the following matrix: | ||
+ | |||
It's easy to imagine this, followed by a Color Matrix primitive, forming the basis of a “pencil sketch” filter chain, but you can achieve a similar result by using the Bias parameter in the filter preferences. This lets you add a fixed offset to the result of each calculation, | It's easy to imagine this, followed by a Color Matrix primitive, forming the basis of a “pencil sketch” filter chain, but you can achieve a similar result by using the Bias parameter in the filter preferences. This lets you add a fixed offset to the result of each calculation, | ||
+ | |||
A variation on edge detection is edge enhancement. This matrix will emphasise edges but still allow the original colors to show through, resulting in a sharpened appearance to the image: | A variation on edge detection is edge enhancement. This matrix will emphasise edges but still allow the original colors to show through, resulting in a sharpened appearance to the image: | ||
+ | |||
Here's another matrix that darkens some edges whilst lightening others, giving rise to an embossed appearance. | Here's another matrix that darkens some edges whilst lightening others, giving rise to an embossed appearance. | ||
As you can see, there are a variety of effects that can be produced with this primitive, although it's far from intuitive to work out what values you need to enter into the matrix to get a particular output. Although the matrix approach allows for a vast number of possibilities, | As you can see, there are a variety of effects that can be produced with this primitive, although it's far from intuitive to work out what values you need to enter into the matrix to get a particular output. Although the matrix approach allows for a vast number of possibilities, | ||
+ | |||
+ | La rotation des valeurs de la matrice de 90 ° (de telle sorte que la ligne du haut contienne 1, 2, 1 et celle du bas -1, -2, -1) la transforme en un filtre de détection des contours horizontaux. Dans ce cas, la moulure disparaît, mais les formes presque horizontales sont accentuées : | ||
+ | |||
+ | Une forme plus générale de détection des contours, qui souligne les lignes verticales et horizontales donnant une version « schématique » de l' | ||
+ | |||
+ | Il est facile d' | ||
+ | |||
+ | Une variation de la détection des contours est l' | ||
+ | |||
+ | Voici une autre matrice qui assombrit certains contours tout en en éclaircissant d' | ||
**Before concluding, there are a few more controls in the filter UI that need to be explained. The Size parameter, as you might expect, sets the size of the matrix. I've only used 3×3 matrices in this article, but 5×5 is also a common size, and you could go higher still, to consider a wider area around each source pixel. Just remember that the size of the matrix defines how many pixels need to be read and calculated for each output pixel, so increasing this parameter can quickly impose a much larger processing burden on Inkscape. | **Before concluding, there are a few more controls in the filter UI that need to be explained. The Size parameter, as you might expect, sets the size of the matrix. I've only used 3×3 matrices in this article, but 5×5 is also a common size, and you could go higher still, to consider a wider area around each source pixel. Just remember that the size of the matrix defines how many pixels need to be read and calculated for each output pixel, so increasing this parameter can quickly impose a much larger processing burden on Inkscape. | ||
Ligne 54: | Ligne 87: | ||
Finally, the Preserve Alpha checkbox determines whether the alpha of the original pixel is transferred to the output unchanged (checked), or if the alpha channel is also subject to the convolution process (unchecked). I tend to leave this checked, as it's one less channel of calculations for Inkscape to perform, and I haven' | Finally, the Preserve Alpha checkbox determines whether the alpha of the original pixel is transferred to the output unchanged (checked), or if the alpha channel is also subject to the convolution process (unchecked). I tend to leave this checked, as it's one less channel of calculations for Inkscape to perform, and I haven' | ||
+ | |||
+ | Avant de conclure, il y a quelques contrôles supplémentaires dans l' | ||
+ | |||
+ | Ici, dans ces exemples, j'ai pris comme base que le centre de la matrice est positionné sur le pixel cible de chaque calcul. Il est possible de changer cela en utilisant le champ Cible de l' | ||
+ | |||
+ | Enfin, la case à cocher Préserver l' | ||
**Image Credits | **Image Credits | ||
“The Creation of Adam” by Michelangelo | “The Creation of Adam” by Michelangelo | ||
https:// | https:// | ||
+ | |||
+ | Crédits images | ||
+ | //La création d' | ||
+ | https:// |
issue114/inkscape.1478245765.txt.gz · Dernière modification : 2016/11/04 08:49 de d52fr