DAY 24
0
Software Development

## [影像處理系列] 當模糊遇上細線化[1]結果分析

=======================分格線=======================

``````int effect(ImageData *img,ImageData *outimg)
{
int fil[9]={
1, 1, 1,
1, 1, 1,
1, 1, 1};
int val;
int x1,y1,x2,y2;
int x,y;
int xx,yy;
int ff;
int rr,gg,bb;
Pixel pix;
x1=0;
y1=0;
x2=img->width-1;
y2=img->height-1;
for(y=y1;y<=y2;y++) {
for(x=x1;x<=x2;x++) {
val=0;
ff=0;
rr=gg=bb=0;
for(yy=-1;yy<=1;yy++) {
for(xx=-1;xx<=1;xx++) {
val = getPixel(img,x+xx,y+yy,&pix);
rr += pix.r * fil[ff];
gg += pix.g * fil[ff];
bb += pix.b * fil[ff];
ff++;
}   }
pix.r=rr/9;
pix.g=gg/9;
pix.b=bb/9;
setPixel(outimg,x,y,&pix);
}   }
return 1;
}
``````

=======================分格線=======================

``````void laplacian(unsigned char image_in[480][640], unsigned char image_out[480][640], double amp, int type)
{
int	i, j;
int d;
int c[3][9] = { 0, -1,  0, -1,  4, -1,  0, -1,  0,
-1, -1, -1, -1,  8, -1, -1, -1, -1,
1, -2,  1, -2,  4, -2,  1, -2,  1};
type = type - 1;
if (type < 0) type = 0;
if (type > 2) type = 2;
for (i = 1; i < 480-1; i++) {
for (j = 1; j < 640-1; j++) {
d = c[type][0] * image_in[i-1][j-1]
+ c[type][1] * image_in[i-1][j  ]
+ c[type][2] * image_in[i-1][j+1]
+ c[type][3] * image_in[i  ][j-1]
+ c[type][4] * image_in[i  ][j  ]
+ c[type][5] * image_in[i  ][j+1]
+ c[type][6] * image_in[i+1][j-1]
+ c[type][7] * image_in[i+1][j  ]
+ c[type][8] * image_in[i+1][j+1];
d = (int)(d * amp) ;
if (d <   0) d = 0;
if (d > 255) d = 255;
image_out[i][j] = (unsigned char)d;
}
}
}
``````

[影像處理系列] 影像模糊化[1] https://ithelp.ithome.com.tw/articles/10194448
[影像處理系列] Laplacian 1至2階微分法 (程式解說) https://ithelp.ithome.com.tw/articles/10192114

=======================分格線=======================

(圖1：原始影像)(影像取自網絡)

*(圖2：把檔案轉換成bmp之影像)

(圖3：把原始影像作1階laplacian處理、放大1.1倍後之影像)

(圖4：把原始影像作1階laplacian處理、放大3.1倍後之影像)

(圖5：把原始影像作2階laplacian處理、放大1.1倍後之影像)

(圖6：把原始影像作2階laplacian處理、放大3.1倍後之影像)

=======================分格線=======================

(圖7：利用3x3 smooth遮罩處理之影像)

(圖8：把3x3 smooth遮罩處理之影像作1階laplacian處理、放大1.1倍後之影像)

(圖9：把3x3 smooth遮罩處理之影像作1階laplacian處理、放大3.1倍後之影像)

(圖10：把3x3 smooth遮罩處理之影像作2階laplacian處理、放大1.1倍後之影像)

(圖11：把3x3 smooth遮罩處理之影像作2階laplacian處理、放大3.1倍後之影像)

=======================分格線=======================

(圖12：利用5x5 smooth遮罩處理之影像)

(圖13：把5x5 smooth遮罩處理之影像作1階laplacian處理、放大1.1倍後之影像)

(圖14：把5x5 smooth遮罩處理之影像作1階laplacian處理、放大3.1倍後之影像)

(圖15：把5x5 smooth遮罩處理之影像作2階laplacian處理、放大1.1倍後之影像)

(圖16：把5x5 smooth遮罩處理之影像作2階laplacian處理、放大3.1倍後之影像)

=======================分格線=======================

(圖17：利用7x7 smooth遮罩處理之影像)

(圖18：把7x7 smooth遮罩處理之影像作1階laplacian處理、放大1.1倍後之影像)

(圖19：把7x7 smooth遮罩處理之影像作1階laplacian處理、放大3.1倍後之影像)

(圖20：把7x7 smooth遮罩處理之影像作2階laplacian處理、放大1.1倍後之影像)

(圖21：把7x7 smooth遮罩處理之影像作2階laplacian處理、放大3.1倍後之影像)

(圖22：把7x7 smooth遮罩處理之影像作2階laplacian處理、放大5.1倍後之影像)

(圖23：把7x7 smooth遮罩處理之影像作2階laplacian處理、放大9.1倍後之影像)

=======================結論=======================

smooth遮罩愈高，laplacian處理也需要更高的階，而且放大率也要更高

=======================分格線=======================