I need some guidance on how to make a selectable grid. I need to make a GUI that allows people to select a box on a grid over an image and make it change colors. So say I have a 25x25 grid over an image. if a person clicks on box 13,20 that box should change to blue. How do i do that?

 Respuesta aceptada

KSSV
KSSV el 9 de Mzo. de 2017
Editada: KSSV el 9 de Mzo. de 2017
N = 25 ;
x = linspace(0,1,N) ;
y = linspace(0,1,N) ;
[X,Y] = meshgrid(x,y) ;
coor = [X(:) Y(:)] ;
I = imread('cameraman.tif');
image([0 1],[0 1],I)
hold on
plot(X,Y,'k') ;
plot(X',Y','k') ;
count = 0 ;
while count == 0
[x,y] = ginput(1) ;
idx = knnsearch(coor,[x y],'k',4) ;
% form bounding box
x0 = min(coor(idx,1)) ;x1 = max(coor(idx,1)) ;
y0 = min(coor(idx,2)) ;y1 = max(coor(idx,2)) ;
% square points
coori = [x0 y0 ; x0 y1 ; x1 y1 ; x1 y0 ; x0 y0] ;
patch(coori(:,1),coori(:,2),'b') ;
end

5 comentarios

Anonymous Matrix
Anonymous Matrix el 9 de Mzo. de 2017
Thanks! that's exactly what i need. But one more question... How do I get the background to be my image? because right now it's a white background but i need to color boxes to cover my image.
KSSV
KSSV el 9 de Mzo. de 2017
Code edited...check it..
Anonymous Matrix
Anonymous Matrix el 9 de Mzo. de 2017
thanks!
Matus Drexler
Matus Drexler el 23 de Mzo. de 2021
Hi.
Is it possible to select possition by e.g. mouse moving with left click?
Mauricio Pereira
Mauricio Pereira el 21 de Nov. de 2022
Hello. How could I code for selecting multiple boxes of the grid at once? For example, click one box of the grid while leaving pressed down the mouse, and finally releasing it.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Image Processing Toolbox en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 9 de Mzo. de 2017

Comentada:

el 21 de Nov. de 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by