影像處理的小demo——Android

來源:互聯網
上載者:User

一、軟體設計的基本原理和採用的主要方法(演算法)與技術

演算法:映像讀入後,把資料放到數組中去。

灰階化用的是最終像素=0.3*R+0.59*B+0.11*G這個公式

反色使用255減去原像素得到最終像素

懷舊效果用的是0.393*R+0.769*G+0.189*B

高斯模糊用的是矩陣的卷積遠算,運算元是1/16{1,2,1,2,4,2,1,2,1},高斯模糊在模糊的同時有考慮每個像素的比重,所以邊緣得以保留下來。

拉普拉斯用的3*3的運算元,{1,1,1,1-8,1,1,1,1}

素描效果的實現參考了ps中的圖層,第一個圖層是灰階圖,第二個圖層是灰階圖反相,然後用最小值濾波,最後是兩個圖層疊加。

圖層的疊加,以灰階圖為基色,處理過的圖層為混合色,結果色=基色+基色*混合色/(255-混合色),最終會使基色圖朝變亮的方向發展,對比增加。

四、實現的過程與步驟

(用visio畫出軟體架構並解釋)

五、遇到的困難與獲得的主要成果

困難:Android平台的Bitmap的一些特性不太熟悉,Bitmap在記憶體中的存貯格式不太清楚,以及canvas的一些屬性和ColorMatrix第一次接觸。

主要成果:Bitmap加深了瞭解,Android平台繪圖的基礎知識有了一個大概的全貌,細節方面還要查api。

六、測試與運行記錄

測試效果、結果

左邊是ps上做的效果,右邊是我的軟體實現的效果。

七、結果分析與小結

開發工作單位基本上達到,影像處理的基礎演算法有了一個比較深入的瞭解,特別是大概實現了映像素描的演算法,濾鏡開發的基礎演算法也比較熟悉了,總的來說,收穫很大。

八、附錄(軟體配置、含注釋的程式模組核心代碼)

public staticBitmap oldbmp(Bitmap bmp){     intwidth=bmp.getWidth();     intheight=bmp.getHeight();         Config config=bmp.getConfig();     Bitmap bitmap=bmp.createBitmap(width, height,Bitmap.Config.RGB_565);//建立一個新的bitmap     intpixColor;     intpixR,pixG,pixb;     intnewColor;     intnewr,newg,newb;     int[]pixs=new int[width*height];     bmp.getPixels(pixs, 0, width, 0, 0, width,height);//把bitmap中的像素提取到pixs數組中去     for(int i=0;i255?255:newr,newg>255?255:newg, newb>255?255:newb);             pixs[i*width+j]=newColor;         }     }     bitmap.setPixels(pixs, 0, width, 0, 0, width,height);     return bitmap; }  public staticBitmap gray(Bitmap bmp){    int width=bmp.getWidth();    int height=bmp.getHeight(); Bitmap bitmap=bmp.createBitmap(width, height,Bitmap.Config.RGB_565);          Canvas canvas=new Canvas(bitmap);//建立一個畫布     Paintpaint=new Paint();//建立一個畫筆     float[] data={(float) 0.3,(float) 0.59,(float)0.11,0,0,(float) 0.3,(float) 0.59,(float) 0.11,0,0,(float) 0.3,(float)0.59,(float) 0.11,0,0,(float) 0.3,(float) 0.59,(float) 0.11,0,0};//灰階圖的顏色過濾矩陣     ColorMatrix coma=new ColorMatrix(data);//以data為參數建立顏色過濾矩陣     ColorMatrixColorFilter filter=new  ColorMatrixColorFilter(coma);//顏色過濾器     paint.setColorFilter(filter);     canvas.drawBitmap(bmp, 0, 0, paint);/在繪製bitmap     return bitmap;} for(inti=1;i=pixcolor?pixcolor:temp;               }    }        newpixs[i*width+j]=temp;    }} int[]Cdata=new int[width*height];//原像素int[]fdata=new int[width*height];//反色的像素int[]temp=new int[width*height];bmp.getPixels(Cdata,0, width, 0, 0, width, height);for(inti=0;itempr?tempr:r;    tempg=g>tempg?tempg:g;    tempb=b>tempb?tempb:b;       //反色像素用最小值濾波           }        }        pixColor=Cdata[i*width+j];        r=Color.red(pixColor);        g=Color.green(pixColor);        b=Color.blue(pixColor);        //原映像與反色並且最小值濾波的映像圖層疊加,用顏色減淡模式        tempr=(int) (r+r*tempr/(256-tempr));        endr=tempr>=255?255:tempr;//顏色減淡的模式,結果色=基色+基色*混合色/(255—混合色)圖層的疊加,以灰階圖為基色,處理過的圖層為混合色,結果色=基色+基色*混合色/(255-混合色),最終會使基色圖朝變亮的方向發展,對比增加。        tempg=(int)(g+g*tempg/(256-tempg));        endg=tempg>=255?255:tempg;        tempb=(int)(b+b*tempb/(256-tempb));       endb=tempb>=255?255:tempb;                      minColor=Color.argb(255,endr, endg, endb);       temp[i*width+j]=minColor;        //min[Color=Color.argb(255,, green, blue)           }}   

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.