我從事基於顏色對象的圖像分割。現在我需要獲取用戶對對象的單擊值以便在另一個對象中使用此信息(單擊值)處理。我如何在matlab中獲得這個值。任何人都可以幫助我。從matlab中的圖像中的任何對象獲取信息
問候
我從事基於顏色對象的圖像分割。現在我需要獲取用戶對對象的單擊值以便在另一個對象中使用此信息(單擊值)處理。我如何在matlab中獲得這個值。任何人都可以幫助我。從matlab中的圖像中的任何對象獲取信息
問候
如果您希望用戶點擊一個情節或圖像,讓他們點擊的座標,您可以使用ginput。例如,
[x,y] = ginput(1);
會給你一個點擊的座標。然後,您可以使用自己的邏輯來確定與哪個對象相對應。
如果這不是你想要做的,你必須更清楚地解釋。
我不知道這是否回答你的問題,但情節的對象(即lines,patches,images等)有ButtonDownFcn
回調,當你按下鼠標按鈕時鼠標指針在對象將執行。
下面是一個簡單的例子(使用nested functions和function handles)您可以如何使用ButtonDownFcn
回調來獲取有關所選對象的信息。首先,保存該函數在m文件:
function colorFcn = colored_patches
selectedColor = [1 0 0]; %# The default selected color
figure; %# Create a new figure
axes; %# Create a new axes
patch([0 0 1 1],[0 1 1 0],'r',... %# Plot a red box
'ButtonDownFcn',@patch_callback);
hold on; %# Add to the existing plot
patch([2 2 4 4],[1 2 2 1],'g',... %# Plot a green box
'ButtonDownFcn',@patch_callback);
patch([1 1 2 2],[3 4 4 3],'b',... %# Plot a blue box
'ButtonDownFcn',@patch_callback);
axis equal; %# Set axis scaling
colorFcn = @get_color; %# Return a function handle for get_color
%#---Nested functions below---
function patch_callback(src,event)
selectedColor = get(src,'FaceColor'); %# Set the selected color to the
%# color of the patch clicked on
end
function currentColor = get_color
currentColor = selectedColor; %# Return the last color selected
end
end
接下來,運行上述代碼並保存返回的函數手柄在一個變量:
colorFcn = colored_patches;
這將創建3個彩色框的圖,像這樣:
現在,當您從colorFcn
點擊鼠標的彩色框一個,輸出將瓚GE:
%# Click the red box, then call colorFcn
>> colorFcn()
ans =
1 0 0 %# Returns red
%# Click the blue box, then call colorFcn
>> colorFcn()
ans =
0 0 1 %# Returns blue
%# Click the green box, then call colorFcn
>> colorFcn()
ans =
0 1 0 %# Returns green
感謝您的回覆......是的,我希望用戶點擊圖像(圖像中的所有對象),並得到他們點擊...如果我得到這個座標可我會努力的座標申請輸入功能...非常感謝你 – zenab 2010-12-02 13:23:29
對於這個錯誤感到抱歉...我會繼續我的問題...如果我得到對象座標,我可以把這個對象看作一個圖像嗎? – zenab 2010-12-02 13:25:39