1 / 31

עיבוד אותות ותמונות במחשב

עיבוד אותות ותמונות במחשב. אלכסנדר ברנגולץ דואר אלקטרוני : aer@cs.technion.ac.il פישבך 346, טל: 4619 שעות קבלה: ב’ 18:30-19:30. היכן תעבדו ?. תואר ראשון : תחנות st194s5-st209s5 UltraSparc בחדר 402 תחנות st100hp-st150hp HP/712/100 בחדר 200 שרת HP/9000/879/K260 csst דרך telnet

nirav
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. עיבוד אותות ותמונות במחשב אלכסנדרברנגולץ דואר אלקטרוני: aer@cs.technion.ac.il פישבך 346, טל: 4619 שעות קבלה: ב’ 18:30-19:30

  2. היכן תעבדו? • תואר ראשון: • תחנות st194s5-st209s5 UltraSparcבחדר 402 • תחנותst100hp-st150hp HP/712/100 בחדר 200 • שרת HP/9000/879/K260 csst דרךtelnet • תואר שני: • שרתSparc Ultra-Enterprise csd דרךtelnet • X-terminals בחדרים שאלות על בעיות במערכת: בדואר האלקטרוניל- helpdesk@cs.technion.ac.il עיבוד תמונות ואותות במחשב

  3. Matlab היא סביבה אינטראקטיבית לחישוב מדעי והנדסיולויזואליזציההמבוססת על מטריצות. מידע בסיסי - הרצאה זו. איך למצוא מידע נוסף: פקודותhelp, helpwin, helpdesk, demoמתוך ה-Matlab באינטרנט: http://www.cs.technion.ac.il/~aer/matlab-help/helpdesk.html Matlab Primer: http://www.technion.ac.il/~aer/Books/Matlab-Primer-4.1.ps.gz העבודה הבסיסית ב-Matlab עיבוד תמונות ואותות במחשב

  4. מטריצות ב-Matlab מטריצות מלבניות הן מבנה הנתונים העיקרי ב-Matlab. כדי להכניס מטריצה פשוט כותבים: • [l=[3 7 11 5 - וקטור-שורה בן 4 אברים • x=0:0.01:1 - וקטור 1x101 אברים • [m=[2;66;11;9 - וקטור-עמודה • [ A=[3 4 5; 4 7 9; 2 6 7 - מטריצה 3x3 • [B=[m m;m m - הרכבת מטריצה מוקטורים • (A=B(3:5, 4:7 - הוצאת תת-מטריצה • ([A=B(:,[1 3 2 4 - החלפת מקום של שני עמודות עיבוד תמונות ואותות במחשב

  5. פעולות עם מטריצות • יצירת מטריצות ייחודיות: (zeros(3,5), ones(6,2 • פקודות על מטריצות, וקטורים ואברים בודדים:+,-,*,/,\,^ a^2 או a+bאו A*x-y • פקודות על אברים מתאימים במטריצות (כמו במערכים): a./b או a.^2 אוa.*b • פונקציות: (sqrt(x), sin(y), exp(a+ib), besselj(k,z עיבוד תמונות ואותות במחשב

  6. plot(x,y), plot(x,sin(x)), plot(sin(2*x),cos(3*x)), semilogy(x,exp(x),x,gamma(x)) figure and figure(k) hold on, hold off, hold mesh(x,y,z), mesh(z), meshc(z) contour(z) subplot(3,1,2) axis([0 22 3 7]), axis([min(x) max(x) -1 1]) Visualization and Graphics עיבוד תמונות ואותות במחשב

  7. Sinc דו-ממדי (דוגמה) • a=-9:.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)’) עיבוד תמונות ואותות במחשב

  8. פקודתif: if (A > B) ‘greater’ elseif (A< B) ‘smaller’ elseif (A == B)‘equal’ else ‘Unexpected situation’ end ifisunix ‘unix’ end ifres(n,2) ~= 0 ‘odd’ else ‘even’ end בקרת הזרימה עיבוד תמונות ואותות במחשב

  9. switch(rem(n,4) ==0)+ (rem(n,2)==0) case 0 ‘odd’ case 1 ‘single even’ case 2 ‘double even’ otherwise error(‘This is impossible’) end רק case אחד מתבצע ! פקודתswitch עיבוד תמונות ואותות במחשב

  10. פקודתfor • לולאה פשוטה: forn=1:4 subplot(2,2,n) plot(a(:,1),a(:,n+1)) title(sprintf(‘n=%d’,n+1) end עיבוד תמונות ואותות במחשב

  11. פקודתfor • לולאה מקוננת: fori=1:25 forj=1:2:41 M=sin(i^2+j^3); end end עיבוד תמונות ואותות במחשב

  12. פקודות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; else b = x; fb = fx; end end עיבוד תמונות ואותות במחשב

  13. פקודותwhileוbreak a = 4; fa=sin(a); b = 2; fb = sin(b); while a - b > 5 * eps x = (a+b)/2; fx = sin(x); if fx == 0 break else if sign(fx) == sign(fa) a = x; fa=fx; else b = x; fb = fx; end end עיבוד תמונות ואותות במחשב

  14. פונקציות ב-Matlab נייצר קובץsolve.m המכיל: functionx=solve(a,b) fa=sin(a); fb = sin(b); while abs(a - b) > 5 * eps x = (a+b)/2; fx = sin(x); if sign(fx) == sign(fa) a = x; fa=fx; else b = x; fb = fx; end end עיבוד תמונות ואותות במחשב

  15. פונקציות ב-Matlab נייצר קובץsolve.m המכיל: functionx=solve(a,b) fa=sin(a); fb = sin(b); while abs(a - b) > 5 * eps x = (a+b)/2; fx = sin(x); if sign(fx) == sign(fa) a = x; fa=fx; else b = x; fb = fx; end end עיבוד תמונות ואותות במחשב

  16. פונקציות ב-Matlab נייצר קובץsolve.m המכיל: function[x,fx]=solve(a,b) fa=sin(a); fb = sin(b); while abs(a - b) > 5 * eps x = (a+b)/2; fx = sin(x); if sign(fx) == sign(fa) a = x; fa=fx; else b = x; fb = fx; end end עיבוד תמונות ואותות במחשב

  17. פונקציות ב-Matlab נייצר קובץsolve.m המכיל: function[x,fx]=solve(a,b) fa=sin(a); fb = sin(b); while abs(a - b) > 5 * eps x = (a+b)/2; fx = sin(x); if sign(fx) == sign(fa) a = x; fa=fx; else b = x; fb = fx; end end עיבוד תמונות ואותות במחשב

  18. פונקציות ב-Matlab נייצר קובץsolve.m המכיל: function[x,fx]=solve(a,b,f) fa=feval(f,a); fb = feval(f,b); while abs(a - b) > 5 * eps x = (a+b)/2; fx = feval(f,x); if sign(fx) == sign(fa) a = x; fa=fx; else b = x; fb = fx; end end עיבוד תמונות ואותות במחשב

  19. בד”כ לא נוח לעבוד בצורה אינטראקטיבית בלבד מאבדים את כל מה שנעשה בין session ל - session לא ניתן לעבוד בעורך (editor) המועדף כדי להפעיל קובץmy_m_file.mפשוט כותבים ב-Matlab את השםmy_m_fileוזה עובד... פקודות שימושיות: load Mydata.dat- טוענת את תוכן הקובץ Mydata.datלמשתנהMydata (יeval(‘Command - מבצעת את ה-”Command” ב-Matlab what - מחזירה את השמות של M-filesבcurrent directory who and whos - מחזירות את שמות המשתנים המוגדרים כעת (s=sprintf(‘Mydata%d’,i - זהה לאותה פקודה ב-C M-files עיבוד תמונות ואותות במחשב

  20. ייצוג תמונה ו-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 עיבוד תמונות ואותות במחשב

  21. ייצוג תמונה ב-Matlab • כמו קודם נייצר(Z=sinc(R עיבוד תמונות ואותות במחשב

  22. ייצוג תמונה ב-Matlab • נתיחסל-Zבתור תמונה(image(100*Z עיבוד תמונות ואותות במחשב

  23. ייצוג תמונה ב-Matlab • נפעיל פקודה שכוללת את הנרמול ל-Z : (imagesc(Z עיבוד תמונות ואותות במחשב

  24. ייצוג תמונה ב-Matlab • אפשר להגדיל גם אתZ: עיבוד תמונות ואותות במחשב

  25. פקודות נוספות • <print -depsc2 <filename - הדפסת תמונה או איור • (im2double(img), im2uint8(img- הופך תמונה • (‘X,map]=imread(‘file] - לקרוא תמונה מקובץ • (imwrite(X,map,’file’,fmt - רשום תמונה לקובץ • (imshow(img,n - להציג תמונה בnרמות אפור עיבוד תמונות ואותות במחשב

  26. חומר מתקדם - תכנות ב-C ל-Matlab • וכעת נרצה לבנות פונקציהmyfuncשנוכל לקרוא לה מתוך Matlab: [x, y]=myfunc(a,b,c) • לשם כך נרשום קובץmyfunc.cובו פונקציה: • נקמפל אותוmex myfunc.cונפעיל... #include <mex.h> void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { mexPrintf("Number of input arguments %d\n", nrhs); mexPrintf("Number of output arguments %d\n", nlhs); } עיבוד תמונות ואותות במחשב

  27. קבלת מידע נוסף על הנתונים #include <mex.h> void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { …} • ([mxGetNumberOfDimensions(phrs[i- מספר ממדים במערך[phrs[i • ([mxGetDimensions(phrs[i- ממדים של מערך[phrs[i • ([mxGetM(phrs[iו([mxGetN(phrs[i - ממדים של מטריצה דו-ממדית • ([void *mxGetData(phrs[i- מצביע להתחלה של נתונים במערך (של Matlab) • ([mxIsInt8(...) ,mxIsComplex(...) ,mxIsDouble(phrs[i- בדיקות אין ב-Matlab שום בדיקה של נכונות הנתונים המועברים לתוכניות חיצוניות. כל הבדיקות על האחראיות הבלעדית של מתכנת הפונקציה. חשוב מאוד עיבוד תמונות ואותות במחשב

  28. נייצר משהו משלנו... • יצירת מטריצת Matlab: • יצירת מערך בממד כלשהו: • אפילו אם כמות משתני יציאה היא אפס, ניתן לכתוב ל- [phls[0,ערכו יישמר במשתנהans בעת חזרה מפונקציה plhs[i] = mxCreateDoubleMatrix(rows, cols, mxCOMPLEX); data_real = mxGetPr(plhs[i]); /* already (double *) */ data_img = mxGetPi(plhs[i]); int dims[]={rows,cols,8,9,11} plhs[i] = mxCreateNumericArray(num_dims, dims, mxINT16_CLASS, mxREAL); data = (short *) mxGetPr(plhs[i]); /* was (double *) */ עיבוד תמונות ואותות במחשב

  29. פונקציות אחרות • (...)mxFree(...) ,mxRealloc(...) ,mxCalloc(...) ,mxMalloc- להבדיל משימושבפונקציות סטנדרטיות של C הפונקציותהאלועובדותעםמנהל זיכרון של Matlab, ולמשל, מפנות זיכרון בסיום של הרצת הפונקציה. • (…)mxDestroyArray-מפנה זיכרון • (…)mxMakeArrayPersistent-אוסר פנוי המערך בסיום הפונקציה. • (...)mxSetM(...) ,mxSetDimensions(...) ,mxSetData-שינוי בנתונים • (“mxSetName(mxArray *,”name - לתת\לשנות שם נרשם במערך • (“mexPrintf(“msg - במקום(“printf(”msg • (“mexWarnMsgTxt(“msg - במקום(“fprintf(stderr,”msg • (“mexErrMsgTxt(“msg - גורם גם לסיום התוכנית. עיבוד תמונות ואותות במחשב

  30. נייצר פונקציה mysin זהה לפונקציה sin הקיימת בMatlab. לשם כך נרשום בקובץ mysin.c: #include <mex.h> void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { mexCallMATLAB(nlhs,plhs,nrhs,prhs,”sin”); } קריאה לפונקציות Matlab מתוכנית עיבוד תמונות ואותות במחשב

  31. טיפול בעצמים הקיימים מחוץ לתוכנית • (“mxArray *mexGetArray(“matrix_name”, “workspace-להוציא מערךבשם “matrix_name” מסביבת עבודה (base, caller, global) • (“mexPutArray(mxArray *, “workspace- להעביר לסביבת עבודה • (“mexEvalString(“Command to execute- לבצע פקודה ב-Matlab • (“mxArray *mexGet(figure,”property - • (* mexSet(figure,”property”, mxArray - טיפול באיורים עיבוד תמונות ואותות במחשב

More Related