issue114:inkscape
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue114:inkscape [2016/11/02 09:40] – créée auntiee | issue114:inkscape [2016/11/09 15:43] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | This month, we're going to look at the Convolve Matrix filter primitive. Convolution is a mathematical term for a process of repeatedly applying one function to the varying output of another function. In the computing world, it's commonly used with discrete values, rather than continuous ones, as you might get when dealing with sampled audio or, indeed, with individual pixels in an image. So, in digital signal processing, convolution generally means using a function to map a series of values to a new series. In SVG filter terms, that means mapping one set of pixels to a new set. The “function” is defined using a matrix of numbers, hence the filter name is “Convolve Matrix” - although “map pixel values using a matrix” would have perhaps made it a little more understandable to the layman. | + | **This month, we're going to look at the Convolve Matrix filter primitive. Convolution is a mathematical term for a process of repeatedly applying one function to the varying output of another function. In the computing world, it's commonly used with discrete values, rather than continuous ones, as you might get when dealing with sampled audio or, indeed, with individual pixels in an image. So, in digital signal processing, convolution generally means using a function to map a series of values to a new series. In SVG filter terms, that means mapping one set of pixels to a new set. The “function” is defined using a matrix of numbers, hence the filter name is “Convolve Matrix” - although “map pixel values using a matrix” would have perhaps made it a little more understandable to the layman. |
- | 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, |
- | 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: | + | Ce mois-ci, nous allons examiner la primitive de filtrage Matrice de convolution. La convolution est le terme mathématique pour le mécanisme d' |
+ | |||
+ | 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: | ||
The convolution process itself consists of taking our matrix and positioning it so that the target cell in the matrix is positioned over each pixel in the input image, in turn. We're going to look at the calculation that takes place for the first black pixel in our input image – the one with the red outline. The 9 pixels covered by the matrix are all multiplied by the corresponding value in the matrix cell, then added together. The result is clamped so that it doesn' | The convolution process itself consists of taking our matrix and positioning it so that the target cell in the matrix is positioned over each pixel in the input image, in turn. We're going to look at the calculation that takes place for the first black pixel in our input image – the one with the red outline. The 9 pixels covered by the matrix are all multiplied by the corresponding value in the matrix cell, then added together. The result is clamped so that it doesn' | ||
The value of the output pixel is therefore: | The value of the output pixel is therefore: | ||
+ | (255×1.00) + (255×1.00) + (255×1.00) + | ||
+ | (255×1.00) + (0×1.00) + (0×1.00) + | ||
+ | (255×1.00) + (0×1.00) + (0×1.00)** | ||
+ | |||
+ | 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 procédé de convolution lui-même consiste à prendre notre matrice et à la positionner de sorte que la cellule cible de la matrice soit tour à tour positionnée au-dessus de chaque pixel de l' | ||
+ | |||
+ | La valeur du pixel de sortie est donc : | ||
(255×1.00) + (255×1.00) + (255×1.00) + | (255×1.00) + (255×1.00) + (255×1.00) + | ||
(255×1.00) + (0×1.00) + (0×1.00) + | (255×1.00) + (0×1.00) + (0×1.00) + | ||
(255×1.00) + (0×1.00) + (0×1.00) | (255×1.00) + (0×1.00) + (0×1.00) | ||
- | It doesn' | + | **It doesn' |
Moving on to the next pixel, we get a similar result. This time there are only three white pixels that contribute to the output, but that's still a value of 765, which gets clamped, so the output is again white. | Moving on to the next pixel, we get a similar result. This time there are only three white pixels that contribute to the output, but that's still a value of 765, which gets clamped, so the output is again white. | ||
Ligne 18: | Ligne 31: | ||
Considering the remaining black pixels in our test image, it's pretty obvious that all the outside ones will turn white. In fact it's only the very center pixel that remains black. So the output from this particular convolution matrix is just a single black pixel at the center of a white square. | Considering the remaining black pixels in our test image, it's pretty obvious that all the outside ones will turn white. In fact it's only the very center pixel that remains black. So the output from this particular convolution matrix is just a single black pixel at the center of a white square. | ||
- | 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.** |
- | 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' | + | 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' | ||
Because the values we've chosen tend to result in calculations that get clamped, our filter, as it stands, pretty much just creates black and white pixels in the output. Before clamping, we were getting results of 1,275 and 765, but we then proceed to throw away any difference between the values because they' | Because the values we've chosen tend to result in calculations that get clamped, our filter, as it stands, pretty much just creates black and white pixels in the output. Before clamping, we were getting results of 1,275 and 765, but we then proceed to throw away any difference between the values because they' | ||
- | 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.** |
- | 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' | + | 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' | ||
+ | |||
+ | 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: | ||
- | 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, | ||
- | 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. |
In the examples here, I've assumed that the center of the matrix is positioned over the target pixel for each calculation. It's possible to change that using the Target fields in the UI, where 0,0 would set the top-left cell of the matrix as the target. All this does is shift the output a little, so there' | In the examples here, I've assumed that the center of the matrix is positioned over the target pixel for each calculation. It's possible to change that using the Target fields in the UI, where 0,0 would set the top-left cell of the matrix as the target. All this does is shift the output a little, so there' | ||
- | 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' |
- | Image Credits | + | 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 | ||
“The Creation of Adam” by Michelangelo | “The Creation of Adam” by Michelangelo | ||
- | https:// | + | https://en.wikipedia.org** |
+ | |||
+ | Crédits images | ||
+ | //La création d' | ||
+ | https://fr.wikipedia.org |
issue114/inkscape.1478076005.txt.gz · Dernière modification : 2016/11/02 09:40 de auntiee