當我接手這個專案時,我認為像黑白/棕褐色這樣的濾鏡很難透過照片處理來製作。一切都變得更簡單!
下面我將給出一個有趣的演算法,用於將影像分解為像素光譜並處理照片。
<h1>Filter Fun</h1> <script src="https://www.dukelearntoprogram.com/course1/common/js/image/SimpleImage.js"> </script> <canvas> <p>I'm hinting at something like this (naturally, any file):<br> <img src="https://img.php.cn/upload/article/000/000/000/173352709543373.jpg" alt="Filtration isn"></p> <p>It is better to align even the simplest design. You will get the hang of big projects faster.<br> </p> <pre class="brush:php;toolbar:false">h1 { font-size: 22pt; font-family: Arial; color: #008B8B; } body { background-color: #F5F5DC; } p { font-size: 16pt; } canvas { width: 400px; background-color: #ADD8E6; border: 2px solid #A9A9A9; } input { font-size: 12pt; }
演算法的本質如下:
var imgFile; var image = null; var imageGray = null; var imageRed = null; var imageRainbow = null; var canvas = null; function loadImage(){ canvas = document.getElementById("can"); imgFile = document.getElementById("file"); image = new SimpleImage(imgFile); imageGray = new SimpleImage(imgFile); imageRed = new SimpleImage(imgFile); imageRainbow = new SimpleImage(imgFile); image.drawTo(canvas); } function imageIsLoaded(img) { if (img==null || !img.complete()) { alert("Image not loaded"); return false; } else { return true; } } function doGray(){ if (imageIsLoaded(image)) { for (var pixel of imageGray.values()) { var arg = (pixel.getRed() + pixel.getGreen() + pixel.getBlue())/3; pixel.setRed(arg); pixel.setGreen(arg); pixel.setBlue(arg); } imageGray.drawTo(canvas); } } function doRed(){ if (imageIsLoaded(image)) { for (var pixel of imageRed.values()) { var arg = (pixel.getRed() + pixel.getGreen() + pixel.getBlue())/3; if (arg < 128) { pixel.setRed(arg*2); pixel.setGreen(0); pixel.setBlue(0); } else { pixel.setRed(255); pixel.setGreen(arg*2-255); pixel.setBlue(arg*2-255); } } imageRed.drawTo(canvas); } } function doRainbow(){ if (imageIsLoaded(image)) { imageRainbow.drawTo(canvas); } } function Reset(){ image = new SimpleImage(imgFile); imageGray = new SimpleImage(imgFile); imageRed = new SimpleImage(imgFile); imageRainbow = new SimpleImage(imgFile); image.drawTo(canvas); }
這似乎是一個簡單的演算法,但它有助於理解影像像素並根據調色板進行處理。我認為它值得你關注!
以上是過濾不是最難的部分的詳細內容。更多資訊請關注PHP中文網其他相關文章!