Labview and Matlab for PT

Just a place to discuss with Matlab and Labview

ad
顯示具有 Matlab影像處理 標籤的文章。 顯示所有文章
顯示具有 Matlab影像處理 標籤的文章。 顯示所有文章

ginput -- A Useful and Convenient Function


Yesterday night, one of junior classmates told me that he found a useful function called "ginput" which can make the thing getting mouse position easier than using "get(gca......)". It's very convenient when designing some program such as calculating angle in coordinate plane. So, here is a very simple example about how to calculate the angle in a certain image.

global flag h_im h_1
filename='D:\07020203_mpg2-0000281.jpg';
im=imread(filename);
h_im=image(im);
while 1
    cal_cord_ang;
end

function cal_cord_ang
global flag h_im h_1
cla(h_im)
[x,y] = ginput(1);
a=[x,y];
x0=a(1,1);
y0=a(1,2);
hold on
h_1=plot(x0,y0,'color','r','marker','+');
[x,y] = ginput(1);
b=[x,y];
x1=b(1,1);
y1=b(1,2);
h_1=plot([x0 x1],[y0 y1],'color','r','marker','+');
[x,y] = ginput(1);
c=[x,y];
x2=c(1,1);
y2=c(1,2);
h_1=plot([x0 x1 x2],[y0 y1 y2],'color','r','marker','+');

% calculate angle by using this formula --> A dot B = ABcos
A=a-b;
B=c-b;
angle=acosd(dot(A,B)/(norm(A)*norm(B)));
x_t=mean([x0 x2]);
y_t=mean([y0 y2]);
text(x_t,y_t,num2str(angle),'color','r')
ginput(1)
cla(h_im)

However, I almost forget the concept of vector, even the product of two vectors. You can review the concept in this url: http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/index.htm.

Try it, it's very funny!!!


[Transcription] Superimposing line plots on image

In my Sonoanalysis program, I need to mark the position I want on the sono image. Before I read this article: Superimposing line plots on image, there are two ways I thought to achieve this task. One is using plot function, and the other is changing the color of the pixel of position I click. However, the later method has a critical problem that it may be a time wasting method if I want to mark the position repeatedly, because I have to change several pixels if the shape of the marker is cross or circle. As a result of that, I choose the first way to accomplish my task finally. Today, I surfed on the internet to seek the correct method to do this kind of thing.


In this article: Superimposing line plots on image, the author who manages the Image & Geospatial development team at the Mathworks shows the way by using plot function, so I think it is a better way to do this task.

Sonoanalysis V.001(初版)

前言:改良自碩士班的原始版本,當初懵懵懂懂寫得很亂,現在以新觀念方法改造。



  1. Load File:開啟後選取圖片資料夾,資料夾內圖片會以[sort_name] = sort_file(path)排列,目的是將連續圖片排序,若是一般則以sort的方式(排列字母大小等)。但是當初因為自己的失誤把檔名寫成1.jpg, 2.jpg ….. 10.jpg, 11.jpg…..,經過排列後會變成1.jpg, 10.jpg, 11.jpg, ……, 19.jpg, 2.jpg, 21.jpg…..,因此才多寫若是檔名不一樣長,則以不同cell的方式將相同長度檔名放入排列(目前只有到十位數)。
  2. Sliderbar:會將sort過得file按照順序排列,提供一張張點選。
  3. position select:則是以sono_mousedown.m方式,將滑鼠點所點的點的座標顯示。
  4. Dist tool:以matlab內建的dist tool作用,不過目前沒有校正顯示的長度。
  5. Save Figure & value:將座標值存入table中,並且將點選好的圖片存入目前資料夾內,並且以[path new_filename] = changefilename(filename,add_word)改名(如:a_原始檔名)。改名之後,由於儲存圖檔的時候當初以plot方式所畫得十字記號無法存入,因此以[change_image] = draw_image(im,x,y)方式,將所選取的座標位置上下左右15個像素統統改成紅色(即變成十字)。
    匯入座標資料於table,並且[cal_dist]=calcu_dist(ini_p,cal_p,dist_prop),依目前深度計算和第一點的距離。
  6. Export:將資料匯出,內建以目前資料夾為匯出處,以[file,path]=uiputfile('.txt','Save file as',eval('[handles.path default_file]'))完成想要匯出的資料夾,預設以dist.txt作為預設匯出檔名。
    匯出後以sonofilemerge(path,sonofile,distfile)自動和sono.txt檔案結合成stiff.txt(個人需要)。