【影象轉換】基於matlab二維圖轉三維圖【含Matlab原始碼 465期】
阿新 • • 發佈:2021-06-28
一、簡介
基於matlab 二維圖轉三維圖
二、原始碼
I=imread('dx.bmp'); %讀入一幅圖片 %I=I(33:375,74:508,:); %須事先人工確定行標和列標 %提取座標框內部分 I1=I(:,:,1); %提取紅色灰度矩陣 pixel_black=(I1==0); number_col=sum(pixel_black); number_row=sum(pixel_black'); j1=find(number_col==max(number_col)); number_col(j1)=-1; j2=find(number_col==max(number_col)); i1=find(number_row==max(number_row)); number_row(i1)=-1; i2=find(number_row==max(number_row)); I=I(min(i1,i2):max(i1,i2),min(j1,j2):max(j1,j2),:); %提取各等高線上顏色灰度值 II=I; II(II==255)=0; II(II>0)=255; BW=II(:,:,1)+II(:,:,2)+II(:,:,3); [row_id,col_id]=find(BW); up_row_id=min(row_id); up_col_id=col_id(round(mean(find(row_id==up_row_id)))); left_col_id=min(col_id); left_row_id=row_id(round(mean(find(col_id==left_col_id)))); pixel_BW=BW(up_row_id:left_row_id,up_col_id); row_id=find(pixel_BW)-1+up_row_id; yanse(:,1:3)=I(row_id,up_col_id,:); %yanse=[0 0 143; % 0 47 255 % 0 223 255 % 143 255 111 % 255 207 0 % 255 31 0 % 127 0 0]; %須事先人工確定各等高線顏色灰度值,用到了getpts函式 [m,n]=size(I(:,:,1)); BW=zeros([m,n]); x_xishu=4/(n-1); y_xishu=4/(m-1); gao=[0.1:0.1:0.7]; %提取各等高線上點的三維座標 xyz=[]; for i=1:7 BW1=BW; BW1(I(:,:,1)==yanse(i,1)&I(:,:,2)==yanse(i,2)&I(:,:,3)==yanse(i,3))=1; [y,x]=find(BW1); xyz=[xyz;1+(x-1)*x_xishu 1+(y-1)*y_xishu gao(i)*ones(size(x))]; end xyz=xyz(1:3:end,:); xyz=[xyz;1 1 0;1 2 0;1 3 0;1 4 0;1 5 0;2 1 0;3 1 0;4 1 0;5 1 0;5 2 0;5 3 0;5 4 0;5 5 0;2 5 0;3 5 0;4 5 0]; x=xyz(:,1); y=xyz(:,2); z=xyz(:,3);
三、執行結果
四、備註
版本:2014a
完整程式碼或代寫加1564658423