2017-02-02 8 views
0

matlabで画像を処理しようとしていますが、画像を10x10のインタラクティブグリッドでオーバーレイする必要があります。インタラクティブなグリッドは、デフォルトの色でクリックしたボックスを修正し、クリックされたセルの位置データを保存します。インタラクティブなグリッドで画像をマスラブにマスクする方法は?

マイコードこれまで:

I = imread('LcmsResult_ImageRng_000280.jpg'); 
imshow(I) 
hold on 
M = size(I,1); 
N = size(I,2); 
a=10; 
b=10; 
for k = 1:a:M 
    x = [1 N]; 
    y = [k k]; 
    plot(x,y,'Color','black','LineStyle','-'); 
    set(findobj('Tag','MyGrid'),'Visible','on') 
end 
for k = 1:b:N 
    x = [k k]; 
    y = [1 M]; 
    plot(x,y,'Color','red','LineStyle','-'); 
    set(findobj('Tag','MyGrid'),'Visible','on') 
end 
hold off 
[x,y] = ginput(2); 
hold on; 
fill([x-10 x x x-10],[y y y+10 y+10],'g'); 

これが私の最初の試みで、私はまだ利用できMATLABツールの私の知識が限られているとして、この問題を解決するための最良の方法を決定しようとしています。あなたは、次のドキュメントを読む必要が

+1

[OK]をクリックします。あなたがこれまでに持っているものを私たちに教えてください。 – toshiomagic

答えて

0

ボタンダウン機能:https://www.mathworks.com/help/matlab/creating_plots/button-down-callback-function.html

マウスクリックをキャプチャ:https://www.mathworks.com/help/matlab/creating_plots/capturing-mouse-clicks.html

パッチ:https://www.mathworks.com/help/matlab/ref/patch.html

RGB色仕様:https://www.mathworks.com/help/matlab/ref/colorspec.html

プロット画像:https://www.mathworks.com/help/images/ref/imshow.html

いくつかの例のコードは次のようになります。

figure 
imshow('imagename.jpg'); 
p = patch([0, 10], [0, 10], [1 1 1]); 
set(p, 'FaceAlpha', 0); % make patch transparent 
set(p, 'ButtonDownFcn', @(~,~)button_down_callback(p),'PickableParts','all'); 

あなたは別途button_down_callback関数を定義する必要があります。

function button_down_callback(p) 
    display('Clicked'); 
    set(p, 'Color', [0.5, 0.9, 0.2], 'FaceAlpha', 0.5); % Change color and set transparency to half 
end 

プログラミングの練習として、イメージを10x10グリッドに分割することをお勧めします。

0

私の作業コード:

function [ ] = defect_marking() 
    % This function divides a figure into grids. The grid cells can be clicked 
    % ,on detecting the click the cell would turn to red. Use keypress to exit 
    % the funtion 
     disp('Defect Function'); 
     pw = waitforbuttonpress; 
     while pw ~= 1 
         cell = 100; % size of single cell 
         col = 11; % maximum number of columns in the grid 
         [c1, c2] = ginput(1);% detect cursor co-ordinates 
         cell_n = (floor(c2/cell)*col)+ (floor(c1/cell)+1); 
         n = cell_n;% index of cell cell number selected 
         n_row = floor(n/col); 
         n_col = mod(n,col); 

    % Calculations for determining co-ordinates for grid cell to be patched. 
         x1= (n_col * cell)- cell;   
         y1= (n_row * cell)+ cell; 

         x2= (n_col * cell); 
         y2= (n_row * cell)+ cell; 

         x3= (n_col * cell);    
         y3 = (n_row * cell); 

         x4= (n_col * cell)- cell;   
         y4= (n_row * cell); 

         x = [x1 x2 x3 x4]; 
         y = [y1 y2 y3 y4]; 

         p = patch(x,y,'red');% applying patch on grid 
         pw = waitforbuttonpress;% updating button press to detect keypress to exit 
     end 
    end 
関連する問題