matlip: matlab-like language for image processing pin-chin huang...

32
MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang ( [email protected] ) Shariar Zaber Kazi ([email protected] ) Shih-Hao Liao ([email protected] ) PoHsu Yeh ([email protected] )

Upload: jeffery-wilcox

Post on 13-Jan-2016

224 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

MATLIP: MATLAB-Like Language for Image Processing

Pin-Chin Huang ([email protected])Shariar Zaber Kazi ([email protected])

Shih-Hao Liao ([email protected])PoHsu Yeh ([email protected])

Page 2: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Motivation• Easy to code Easy to access pixels of an image Easy to do image arithmetic operation Easy to do image convolution Easy to assign images of any size Easy to debug

• No cost for license

• Good Portability

Page 3: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Easy to access one pixel of an image

function = main() image x; x=imread("./rabbit.jpg"); print(x[1,1,"RGB"]);end

public static void main(String[] args){BufferedImage x = imnew(100, 100, "RGB");x = imread("./rabbit.jpg");System.out.println(getImagePixel(x, 1, 1, "RGB"));}static int getImagePixel(BufferedImage im, int col,

int row, String channel){

…………………………

}

26 lines of java code

Page 4: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Easy to do image arithmetic operation

function = main() image x; image y; x=x+1; x=x-1; x=x*1; x=x/1; x=x+y;end

public static void main(String[] args){BufferedImage x = imnew(100, 100, "RGB");BufferedImage y = imnew(100, 100, "RGB");x = imread("./rabbit.jpg");x = (BufferedImage)clone((BufferedImage)doArithmetic(x, 1, OPERATION.ADD));x = (BufferedImage)clone((BufferedImage)doArithmetic(x, 1, OPERATION.SUB));x = (BufferedImage)clone((BufferedImage)doArithmetic(x, 1, OPERATION.MUL));x = (BufferedImage)clone((BufferedImage)doArithmetic(x, 1, OPERATION.DIV));x = (BufferedImage)clone((BufferedImage)doArithmetic(x, y, OPERATION.ADD));}static Object doArithmetic(Object op1, Object op2, OPERATION op){……………}static Object clone(Object src){……………………}

150 lines of java code

Page 5: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Easy to do image convolution

function = main() image x; kernel k; x=x@k;end

public static void main(String[] args){BufferedImage x = imnew(100, 100, "RGB");Kernel k = kernelinit();x = (BufferedImage)clone(convolve(x, k));}static BufferedImage convolve(BufferedImage im, Kernel k){………………….}static Object clone(Object src){…………………….}

45 lines of java code

Page 6: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Easy to assign image to image of different size

function = main() image a; image b; a = imnew(300,300,"RGB"); b = imnew(200,200,"RGB"); a=b; end

public static void main(String[] args){BufferedImage a = imnew(100, 100, "RGB");BufferedImage b = imnew(100, 100, "RGB");a = imnew(300, 300, "RGB");b = imnew(200, 200, "RGB");a = (BufferedImage)clone(b); }static BufferedImage imnew(int width, int height, String type){…………..}static Object clone(Object src){………………………}

50 lines of java code

Page 7: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Easy to debug

function = main() int i; for i=0:(int y):100 x=x+1; end y=0;end

syntax error in line #3Fatal error: exception Parsing.Parse_error

Fatal error: exception Failure("Type mismatch in argument passing between: 'x', type: int and 'x', type: float in function: 'test'“)

function int m = test (int x) endfunction = main () float x; x=1.0; test(x);end

Page 8: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Easy to debug

function int m = test () endfunction = main () int x; x=1; test(x);end

Fatal error: exception Failure(“Wrong number of arguments passed to function: ‘test’”)

Fatal error: exception Failure("Cannot concatenate image type with string type in function: 'main'")

function = main() image x; imshow(x); x = imread("./rabbit.jpg"+x); imshow(x); imsave(x,"./rabbit.jpg"); x = imnew(300,300,"RGB"); imshow(x);end

Page 9: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

No cost for licenseImage Processing Toolbox 6.2 (MATLAP)• Individual License

For: End userActivation types: Standalone named user or designated computer

• $1,000• Buy

Request a Quote (via fax or e-mail)Contact Sales

• For an end user who wants to personally install, administer, and operate the software.

• Group License For: WorkgroupActivation Types: Standalone named users or designated computers

• Request a Quote (via fax or e-mail)Contact Sales

• For organizations who would like to designate an administrator to manage a group of Individual licenses.

Page 10: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Tutorial introduction

• Variable declaration and assignment:int a;float b;boolean c;kernel k;image i;function = main()a=1;b=0.1;c=true;k=kernelnew(10,10);k=[0.0,0.1;0.3,0.4];i=imnew(10,10,”RGB”);end

int a=3;float b=0.3;boolean c =true;Kernel k=kernelnew(10,10);Image i=imnew(10,10,”RGB”);

Page 11: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Arithmetic Operation

Int a;Int b;float c;float d;funciton = main()a=a+b;a=a-b;a=a*b;a=a/b;a=a^b;a=mod(a,b);c=c+d;c=c-d;c=c*d;c=c/d;end

image a;image b;int c;function =main()a=a+b;a=a-b;a=a*b;a=a/b;a=a*2+b;a=a*c+b;a=a*2.0; (NOT OK)a=2*a;(NOT OK)end

kernel k1;kernel k2;float a;function = main()k1=k1+k2;k1=k1-k2;k1=k1*k2;k1=k1/k2;k1=k1*2.0+k2;k1=k1*a+k2;k1=k1*2+k2;(NOT OK)k1=2.0*k1+k2;(NOT OK)end

Page 12: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Control Flow Statement

int x;function=main()x=1;If x==1 x=x+1;elseif x==2 x=x+2;elseif x==3 x=x+3;else x=x+4;endend

int x;funciton=main()x=1;If x==1 x=x+1;endend

Int x;function=main()x=1;if x==1x=x+1;elseif x==2x=x+2;end

Int x;function=main()x=1;if x==1x=x+1;else x=x+2;end

Page 13: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Control Flow Statement

function = main()int x;int i;for i=0:1:10 x=x+1;endend

function = main()Int x;while x<3 x=x+1;endend

Page 14: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Function

function = test()end function main()test();end

function main()Int d;d=test();Endfunction int m= test()end

function int m= test(int x) m=d;end function main()Int d;d=test(d);end

Page 15: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Recursion

function int m = foo (int x) if(x > 0) m=foo(x-1); else m=-1; endendfunction int m = bar (int x) m=x+1;endfunction = main() print(foo(bar(foo(5))));end

Page 16: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Example (Flip the image vertically)

Page 17: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Example (Flip the image vertically)

function image ret = flip(image im)int height;int width;int i;int j;height = getheight(im);width = getwidth(im);ret=imnew(width,height,"RGB");for j=0:height-1 for i=0:width-1 ret[i,height-j-1,"rgb"]=im[i,j,"rgb"]; endendend

function = main() image x; image y; x=imread("./rabbit.jpg"); imshow(x); y=flip(x); imshow(y); end

Page 18: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Example (Flip the image vertically)

Page 19: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Example (Flip the image horizontally)

function image ret = flip(image im) int height; int width; int i; int j; height = getheight(im); width = getwidth(im); ret=imnew(width,height,"RGB"); for j=0:height-1 for i=0:width-1 ret[width-i-1,j,"rgb"] = im[i,j,"rgb"]; end endend

function = main() image x; image y; x=imread("./rabbit.jpg"); imshow(x); y=flip(x); imshow(y);end

Page 20: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Example (Flip the image horizontally)

Page 21: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Example (Blur the image)

function = main() image x; image y; kernel k; k= [0.25,0.0,0.25;0.0,0.0,0.0;0.25,0.0,0.25]; x=imread("./rabbit.jpg"); #x=togray(x); imshow(x); y=x@k@k@k@k@k@k@k; imshow(y); imsave(y,"./r3.gif"); end

Page 22: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Example (Blur the image)

Page 23: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Example (Sharpen the image)

function = main() image x; image y; kernel k; k= [0.0,-1.0,0.0;-1.0,5.0,-1.0;0.0,-1.0,0.0];

x=imread("./rabbit.jpg"); imshow(x); y=x@k@k; imshow(y); imsave(y,"./r4.gif");end

Page 24: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Example (Sharpen the image)

Page 25: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Example (Inverse the image)function = main() image x; int i; int j; int width; int height; x=imread("./rabbit.jpg"); width=getwidth(x); height=getheight(x); imshow(x); for j=0:height-1 for i=0:2:width-1 x[i,j,"R"] = 255-x[i,j,"R"]; x[i,j,"G"] = 255-x[i,j,"G"]; x[i,j,"B"] = 255-x[i,j,"B"]; end end imshow(x);end

Page 26: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Example (Inverse the image)

Page 27: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Example (Rotate the image 900)function image ret = rotate90(image im) int height; int width; int i; int j; height = getheight(im); width = getwidth(im); ret=imnew(height,width,"RGB"); for j=0:height-1 for i=0:width-1

ret[height-j-1,i,"rgb"] = im[i,j,"rgb"]; end endendfunction = main() image x; image y; x=imread("./rabbit.jpg"); imshow(x); y=rotate90(x);end

Page 28: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Example (Rotate the image 900)

Page 29: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Edge Detection

kernel k;int i;int j;function image m=edge(image b,kernel k) imshow(b); b = b@k; for i=0:getheight(b) for j=0:getwidth(b) if b[j,i,"grey"] < 0 b[j,i,"grey"] = -b[i,j,"grey"]; end end end imshow(b); imsave(b,"./lena_edge.jpg");end

function = main() image a; image b; a = imread("./lena_color.jpg"); b = togray(a); k = [-5.0, 0.0, 0.0; 0.0, 0.0, 0.0; 0.0, 0.0, 5.0]; edge(b,k); end

Page 30: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Edge Detection

Page 31: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Architectural diagram

Page 32: MATLIP: MATLAB-Like Language for Image Processing Pin-Chin Huang (ph2249@columbia.edu)ph2249@columbia.edu Shariar Zaber Kazi (szk2103@columbia.edu)szk2103@columbia.edu

Lesson learned

• Whenever changes are made, do regression test immediately.

• Try to come up with a complete test suite before language design

• Use Version Control System• Try to finish the grammar before

implementation