1 / 49

עיבוד תמונות

עיבוד תמונות. שנת לימודים תשס"ד , סמסטר א'. מרצה: ד"ר דב מלונק מכללת עמק הירדן. עיבוד תמונות. תרגול מספר 1. רשימת נושאים. תרגיל - Matlab. ארגון הקורס. מרצה : ד"ר דב מלונק שעת הרצאה: יום ג' 8:15-9:45 שעות קבלה: יום ג', בחדר ההרצאה, בסיום השיעור אמצעי קשר: dovm@netvision.co.il

freya-house
Download Presentation

עיבוד תמונות

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. עיבוד תמונות שנת לימודים תשס"ד , סמסטר א' מרצה: ד"ר דב מלונק מכללת עמק הירדן

  2. עיבוד תמונות תרגול מספר 1

  3. רשימת נושאים תרגיל - Matlab

  4. ארגון הקורס מרצה : ד"ר דב מלונק שעת הרצאה: יום ג' 8:15-9:45 שעות קבלה: יום ג', בחדר ההרצאה, בסיום השיעור אמצעי קשר: dovm@netvision.co.il 066-747575 ביבליוגרפיה R. C. Gonzalez and R. E. Woods, “Digital Image Processing”, 2nd ed., Prentice-Hall, 2002. עיבוד ספרתי של תמונות - דורון בן צבי, זאב ויסמן - אוניברסיטה פתוחה

  5. שקלול הציון אופן מילוי הדרישות דרישות הקורס 20% חמישה או ששה גיליונות תרגילים תרגילי בית 20% בוחן אמצע 60% בחינת גמר ארגון הקורס תרגילי בית יינתנו כל שבועיים - שלושה . הגשת התרגילים כעבור שבועיים, בתחילת השיעור. ללא איחורים. אפשרות להגשה אלקטרונית תיבדק - פרטים בהמשך . הגשת שיעורי בית בזוגות. ציונים יינתנו בהתאם לאיכות העבודה וצורת ההגשה. יש להדפיס עבודות

  6. Matlab היא סביבה אינטראקטיבית לחישוב מדעי והנדסי,ויזואליזציה ותכנון אלגוריתמים. איך למצוא מידע נוסף: פקודות help, helpwin, helpdesk, demoמתוך ה -Matlab באינטרנט: http://www.mathworks.com/support/ העבודה הבסיסית בMatlab -

  7. פעולות פשוטות • % Comment • Assignment • num = 6 assignment & display • num = 6; assignment

  8. מטריצות ב- Matlab מטריצות מלבניות הן מבנה הנתונים העיקרי :כדי לבנות מטריצה פשוט כותבים: • a=[0.2,7,11,5] - וקטור-שורה (אופרטור , שרשור לאורך שורה) • x=5:2:11 -וקטור ]5,7,9,11[= x (אופרטורa:b:c ) • m=[2.1;66;11;9]עמודהוקטור • A=[3 4 5; 4 7 9; 2 6 7] - 3X3 מטריצה • הרכבת מטריצה מתת מטריצותB=[a b;c d] • העתקת תת מטריצה A=B(3:5, 4:7) • הוצאת עמודות מסוימות מהמטריצה BA=B(:,[1 3 2 4]) • A=B’ - (transpose)שחלוףמטריצה • יצירת STRING : w=‘I am a string’

  9. 1 2 3 4 5 6 7 8 9 מטריצות • mymatrix = [1 2 3; 4 5 6; 7 8 9] • mymatrix = • mymatrix = (:;1) • mymatrix = 1 4 7

  10. 4 5 6 1 2 3 4 5 6 7 8 9 מטריצות • mymatrix = (2,:) • mymatrix = • mymatrix = (1:2,1:2) • mymatrix = 1 2 4 5

  11. 0 0 3 0 0 6 7 8 9 1 2 3 4 5 6 7 8 9 מטריצות • mymatrix(1:2,1:2) = [ 0 0; 0 0] • mymatrix =

  12. 1 2 3 4 5 6 7 8 9 מטריצות • [row col]= size(mymatrix) • row =3 col = 3 • mymat2 = [1 0 0; 0 2 0; 0 0 3]; • x = mymatrix * mymat2 x = 1 4 9 4 10 18 7 16 27

  13. 1 2 3 4 5 6 7 8 9 1 0 0 0 2 0 0 0 3 מטריצות • y = mymatrix .* mymat2 • y = • 0 0 • 0 10 0 • 0 0 27

  14. אופרטורים • Arithmetic • + - * / ^ • Element-by-element matrix operations: • + - .* ./ • Matrix multiplication: • * • Relational • ==, >=, >, <=, <, ~= • Logical • &, |, ~ (element-by-element for matrices)

  15. פונקציתfind ותנאים לוגיים • find(a==3) מחזירה אינדקסים בa לאיברים שמקיימים את התנאי הלוגי. הפונקציה מחזירה אינדקס יחיד במטריצה (שרץ לאורך העמודות) או זוג אינדקסים (y,x) (תלוי במספר פרמטרי החזרה) • a=[1 2 3;4 5 6;7 8 9] • a = • 1 2 3 • 4 5 6 • 7 8 9 • » z=find(a>7) • z = • 6 • 9 • » [y,x]=find(a>7) • y = • 3 • 3 • x = • 2 • 3

  16. פעולות עם מטריצות • יצירת מטריצות ייחודיות: (zeros(3,5), rand(5,1) ones(6,2),eye (6,2 • הפעלת פונקציות:(sqrt(x), sin(y), exp(a+b), result=isempty(a [v,d] = eig(x) • S=sum(A) %S is a row vector of the columns sums of A • S=sum(sum(A)) %sum of matrix A • [NumRows , NumColumns]=size(M)

  17. כמה פונקציות חשובות • conv2(image, conv_matrix) • JPEG images -> n x m x 3 • image = image(:,:,1)

  18. כמה פונקציות חשובות • image = imread(‘goldy.jpg’) • If you use the ppm files, remove the comments at the beginning of the file. • imshow(output_image); figure; imshow(output_image2);

  19. כמה פונקציות חשובות • subplot(1,2,1); imshow(im1); subplot(1,2,2); imshow(im2);

  20. כמה פונקציות חשובות • Type casting is possible. If a function gives type error, use casting. v1 = double(v2);

  21. כמה פונקציות חשובות • Measuring elapsed time: • im = imread(‘goldy.jpg’); tic; im = conv2(im,conv_kernel); toc; elapsed time = 0.1081

  22. כמה פונקציות חשובות • zeros(n,m) • ones(n,m) • clear variable_name clear function –clears all functions from memory clear global -clears all global variables -useful in recursive code

  23. פונקציות • שם הפונקציה כמו שם קובץ ה .m • function[out] = func_name(inp1, inp2,…) • ex. • function[sum]=myadd(inp1,inp2) sum = inp1 + inp2 • c = myadd(3,6) c = 9 • c = myadd(3.5, 6.7) c = 10.2000

  24. פונקציות • פרמטרים מועברים בהעתקה לפונקציה • לא מעשי לשימוש רקורסיבי • השתמש במשתנים גלובליים • global var_name; • See tic.m

  25. רמזים חשובים • השתמש בפקודות tic, toc לגלות חלקים איטיים בקוד • השתמש בתמונות קטנות לבדוק את הקוד • השתמש ב ; כדי לא להדפיס תמונות גדולות • וודא שהתמונות נכונות לפני הדפסה - (לחסוך בנייר(

  26. plot(x,y), plot(x,sin(x)) %plot 1-D function figure , figure(k)%open a new figure hold on, hold off mesh(x_ax,y_ax,z_mat)%view surface contour(z_mat) %view z as top. map subplot(3,1,2) %several plots in figure axis([xmin xmax ymin ymax]) title(‘figure title’) %add title to figure גרפיקה ותצוגה

  27. »Help eig EIG Eigenvalues and eigenvectors. E = EIG(X) is a vector containing the eigenvalues of a square matrix X. [V,D] = EIG(X) produces a diagonal matrix D of eigenvalues and a full matrix V whose columns are the corresponding eigenvectors so that X*V = V*D. » lookfor differentiation NUDERST Selects the step size for numerical differentiation DIFF Alternative entry to the symbolic differentiation function. In unix: !ls or !mkdir כדי לקבל עזרה על פונקציה: help func_name כדי לחפש פונקציה ששמה לא ידוע lookfor keyword כדי לקבל כלי עזרה אינטראקטיביhelpwin/helpdesk איזה משתנים קיימים בשדה העבודהwhos פקודות למ"ה : !command עזרה ב- matlab

  28. Sinc דו-ממדי (דוגמה) • a=-9:0.2:9; • [x,y] = meshgrid(a); • R = sqrt(x.^2+y.^2)+eps; • Z = sin(R)./R; • mesh(a,a,Z) או mesh(x,y,Z) • title(‘Sinc(x^2+y^2)’)

  29. פונקציות ב- Matlab מכיון שmatlab הואinterpreter ניתן לתת לו לבצע פקודות דינמיות (שלא ידועות בזמן קומפילציה): שיטה זו שימושית כשכותביםscript (אוסף פקודות השמור כ filename.mומתבצע בסביבה הגלובלית כאשר רושמיםfilename )ובפונקציות (כמו script אבל מקבלת ומחזירה פרמטרים ועובדת עם משתנים לוקליים בסביבה פנימית). comm=input(‘enter a command name’); op=input(‘enter the argument’); feval(comm,op); %executes comm with op Or eval([comm ‘(‘ op ‘);’ ]); %the same

  30. בד”כ לא נוח לעבוד בצורה אינטראקטיבית בלבד מאבדים את כל מה שנעשה ביןsession ל - session ניתן לעבוד בעורך (editor) המועדף או בעורך של matlabע”י edit. כדי להפעיל my_m_file.m scriptפשוט כותבים בMatlab את השם my_m_fileוזה מריץ את הפקודות סדרתית בסביבה הגלובלית. פקודות שימושיות: whatמחזירה את השמות של קבציmatlab בcurrent directory which imshow מחזיר את מקור הקובץ עם path מלא s=sprintf(‘Mydata%d’,I) - זהה לאותה פקודה ב- C Diary(‘diary_file’), diary offמקליט כל העבודה לקובץ . M-files

  31. ספריות החיפוש של Matlab • חיפוש הקבצים מבוצע בכל הספריות המופיעות ב- CD וב- path • ניתן לכתוב cd או path על מנת לראות את תוכנם. • ניתן לכתוב: cd d:\mydir על מנת לשנות את ספרית העבודה העכשוית. • ניתן לכתוב: path(path,’d:\mydir’) על מנת להוסיף את d:\mydir ל- path (לא נשמר ביציאה מ- Matlab) • ניתן להשתמש גם ב- Path browser

  32. שמירת workspace • הפקודהwhos מציגה את המשתנים שבזיכרון. • הפקודהsave file_name שומרת משתנים אלה בקובץfile_name.mat וניתן לשחזר משתנים אלה לתוך הזיכרון ע"יload file_name • הפקודהclear a מוחקת את משתנהa הפקודהclear מוחקת את כל המשתנים שבזיכרון.

  33. פקודת if: if (A > B), statement; elseif (A< B), statement; elseif ~A,statement; else, statement; end ifi==1, statement; end ifres(n,2) ~= 0, statement; else, statement; end בקרת הזרימה

  34. switch (rem(n,3) ==0) & (rem(n,2)==0) case 0 disp('n is not dividable by 6') case 1 disp('n is dividable by 6') otherwise error('This is impossible') end אין גלישה כמו ב C פקודת switch

  35. פקודת for • לולאה פשוטה: forn=1:1:4, subplot(2,2,n) plot(a(:,1),a(:,n+1)) title(num2str(n)) end

  36. פקודות while a = 4; fa=sin(a); b = 2; fb = sin(b); while a - b > 5 * eps, x = (a+b)/2; fx = sin(x); if sign(fx) == sign(fa), a = x; fa=fx; break; else b = x; fb = fx; end end

  37. ייצוג תמונה ב- Matlab 95 102 94 102 95 98 102 99 103 105 110 94 99 94 101 100 98 100 101 101 107 104 97 86 83 97 96 98 104 96 100 102 102 105 91 85 93 89 98 92 95 98 100 102 106 105 99 90 93 96 84 88 93 89 89 98 94 102 99 81 87 86 84 90 91 88 101 104 87 82 90 84 86 87 86 95 102 99 102 90 74 92 101 87 74 77 83 100 92 95 102 100 92 96 110 93 72 71 83 101 87 103 101 105 88 76 94 93 71 69 105 99 105 104 111 101 84 59 78 102 72

  38. ייצוג תמונה ב- Matlab • כמו קודם נייצר את Z=sinc(R)ע“י mesh Z היא מטריצה המוצגת כאן כמשטח

  39. ייצוג תמונה ב- Matlab • נתיחס ל-Z (הגובה) בתור תמונה imshow(Z,[]) • הבהירות של הפיקסל (x,y) בתמונה מתאימה לגובה z(x,y)

  40. ייצוג תמונה ב- Matlab • אפשר להגדיל גם אתZ ע"יzoom on וסימון ע"י עכבר • אפשר גם בלחצן בחלון הגרפי

  41. ?Image Processing Toolbox • חבילת תוכנה שמאפשרת ביצוע של פעולות רבות של עיבוד תמונה בעזרת פונקציות יעודיות : • Geometric operations • Neighborhood and block operations • Linear filtering and filter design • Transforms • Image analysis and enhancement • Binary image operations • Region of interest operations

  42. סוגי תמונות ב Matlab • Indexed images : m-by-3 color map • Intensity images : [0,1] or uint8 • Binary images : {0,1} • RGB images : m-by-n-by-3

  43. Indexed Images » [x,map] = imread('trees.tif'); » imshow(x,map);

  44. Intensity Images » image = ind2gray(x,map); » imshow(image);

  45. Binary Images »imshow(edge(image));

  46. RGB Images

  47. הצגת תמונות • image - create and display image object • imagesc - scale and display as image • imshow - display image • colorbar - display colorbar • getimage- get image data from axes • truesize - adjust display size of image • zoom - zoom in and zoom out of 2D plot

  48. התמרת תמונות • gray2ind - intensity image to index image • im2bw - image to binary • im2double - image to double precision • im2uint8 - image to 8-bit unsigned integers • im2uint16 - image to 16-bit unsigned integers • ind2gray - indexed image to intensity image • mat2gray - matrix to intensity image • rgb2gray - RGB image to grayscale • rgb2ind - RGB image to indexed image

  49. פקודות נוספות • print -djpeg filename – הדפסתfigure לקובץ filename.jpeg • [X,map]=imread(‘file’) - לקרוא תמונה מקובץ לתוך משתנה X • imwrite(X,map,’file’,fmt) - רשום תמונה שבX לקובץfile בפורמטfmt • imshow(img,n) - להציג תמונה ב nרמות אפור • a=imcrop(img)- לחתוך תת תמונה ע“י סימון עם העכבר • imresize(img,[10 10],’method_name’) לשנות גודל תמונה ל-10X10 • Zoom on, zoom off • colormap(gray מתרגם ערכי המטריצה לתמונה לגווני אפור

More Related