嗚嗚喔學習筆記: MATLAB初體驗(讀圖 放大縮小 混色 補色)

搜尋此網誌

2013年10月4日 星期五

MATLAB初體驗(讀圖 放大縮小 混色 補色)





執行方法:





1.程式碼(讀圖):

clear all; clc;%清空%
filepath=['C:\Users\student\Desktop\caribou'] %圖片路徑%
c=imread(filepath,'tiff');%tiff = 副檔名%
imshow(c);%Show出圖片%



2.程式碼(放大縮小):

clear all; clc;
filepath=['C:\Users\student\Desktop\caribou'] %路徑%
x=imread(filepath,'tiff');%副檔名%

x2=imresize(imresize(x,1/2),2);%變 1/2 倍 在變2倍 會模糊圖片%
figure(3),imshow(x2);%輸出figure(3)->x2%

x3=imresize(imresize(x,1/16),16);
figure(4),imshow(x3);




3.程式碼(混色):

clear all; clc;
filepath=['C:\Users\student\Desktop\caribou'] %路徑%
x=imread(filepath,'tiff');%副檔名%
x=double(x);
D=[0 128; 192 64];
r=repmat(D,128,128);
x2=x>r;
imshow(x2);




4.程式碼(補色):
clear all; clc;
filepath=['C:\Users\student\Desktop\caribou'
b=imread(filepath,'tiff');

figure(1),imshow(b);
bc=imcomplement(b);%補色%
figure(2),imshow(bc);


















3 則留言:

  1. 您好 我想請問一下
    我打到x2 = x>r ;這邊
    一直出現

    Error using >
    Matrix dimensions must agree.

    把x2=x>r改成x2=(x,r)還是一樣耶@@
    我的圖是正方型沒錯
    旁邊側欄也有確定出現x r 這兩個變數
    所以一直想不通@@.....

    感謝回答><

    回覆刪除
    回覆
    1. 錯誤意思是說 圖片大小不符合
      試試看把 128 128 改成你圖片的長寬試試

      刪除
  2. 我也是出現同個錯誤耶
    圖片用128 128也是一樣
    不知道為什麼

    感謝板主回答~

    回覆刪除