Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Canvas APIを使った画像処理入門 / Image Processing Using Canvas API

Canvas APIを使った画像処理入門 / Image Processing Using Canvas API

Canvas APIの使い方から、画像処理の方法、フィルタのアルゴリズム、画像処理フィルタの応用例を紹介

Canvasを用いた9つの画像処理フィルターとそのアルゴリズムの解説
https://kuroeveryday.blogspot.com/2017/10/image-filters-with-canvas-algorithm.html

https://twitter.com/bc_rikko

ダーシノ

April 18, 2019
Tweet

More Decks by ダーシノ

Other Decks in Programming

Transcript

  1. このスライドの内容 1. Canvas APIの使い方 2. 画像処理の方法 3. 画像処理アルゴリズムと用途 1. 二値化

    2. ガンマ補正 3. シャープ化 4. メディアンフィルタ 5. モザイク 4. 画像処理の応用
  2. 画像の読み込み const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); const

    img = new Image(); img.addEventListener('load', e => { canvas.width = img.width; canvas.height = img.height; ctx.drawImage(img, 0, 0); }); img.src = ‘/path/to/rena.png';
  3. ImageData.data 1px毎のRGBAが一次元配列として入っている 例: [r, g, b, a, r, g, b,

    a, …] 走査して画像処理を行う canvas.width×4 canvas.height×4
  4. シャープ化 エッジ(輪郭)を検出・強調するフィルター 画像のボケやブレを解消する [ −1 −1 −1 −1 10 −1

    −1 −1 −1 ] 周囲9ピクセルにそれぞれ係数をかけた値を合計 最後に2で割る
  5. モザイク ブロック単位で不可逆変換するフィルター いろいろ隠したいときに使われる S S S S S S S

    S S S S S S S S S S S r′ = 1 n n ∑ i=1 ri n×nのブロック内の 平均値で塗りつぶす