映像放大演算法(馬賽克效果)

來源:互聯網
上載者:User
映像放大即把較小的映像繪製在較大的空白映像上。這隻介紹馬賽克效果的原理以及類比實現。

可以看出,馬賽克效果的映像放大就是原始像素點的放大。
類比實現演算法:
C#:class Program
{
    static void Main(string[] args)
    {
        int[,] a = new int[,] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 } };

        Print(Enlarge(a, 4));
    }

    static int[,] Enlarge(int[,] src, int zoom)
    {
        if (zoom < 1)
        {
            throw new IndexOutOfRangeException("放大倍數不能小於1");
        }

        if (zoom == 1)
        {
            return src;
        }

        int[,] dst = new int[src.GetLength(0) * zoom, src.GetLength(1) * zoom];

        for (int i = 0; i < dst.GetLength(0); i++)
        {
            for (int j = 0; j < dst.GetLength(1); j++)
            {
                dst[i, j] = src[(i / zoom) % (zoom * zoom), (j / zoom) % (zoom * zoom)];
            }
        }

        return dst;
    }

    static void Print(int[,] array)
    {
        for (int i = 0; i < array.GetLength(0); i++)
        {
            Console.WriteLine("");

            for (int j = 0; j < array.GetLength(1); j++)
            {
                Console.Write(" " + array[i, j]);
            }
        }
    }
}

如果要實現更逼真的映像放大效果,原始映像相鄰兩個像素點放大後它們之間可用兩個像素點的過度色進行填充,也就是插值演算法,有二次插值和多次插值等,其實質可以是貝茲路徑演算法或其他近似演算法。映像放大如果沒有特殊演算法的最佳化,產生的映像不可避免的變地模糊或出現馬賽克。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.