Borrar filtros
Borrar filtros

How to store a color and location in a matrix?

2 visualizaciones (últimos 30 días)
Sang
Sang el 25 de Oct. de 2022
Editada: Stephen23 el 30 de Oct. de 2022
I am trying to locate the colors in this image and put them into a matrix. My thoughts were to somehow define the colors, then mark their location and put them into a 3x3 matrix. I also have a BW image of this. This is for a Rubiks cube, so all sides will have to be checked like this, then be compiled into a 3d model of the cube. From there I should be able to figure out a way to solve it.
  2 comentarios
Sang
Sang el 25 de Oct. de 2022
any one there having the answer ..please reply.....
Sang
Sang el 25 de Oct. de 2022
any one there please answer....

Iniciar sesión para comentar.

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 25 de Oct. de 2022
Editada: KALYAN ACHARJYA el 25 de Oct. de 2022
#Easy way (Not Efficient too)
test_image=imread('image_file_name.jpeg'); %Change the image file name with format
[rows,clom,ch]=size(test_image);
cell_data=cell(rows,clom);
for i=1:2%rows
for j=1:2%colm
cell_data{i,j}=[test_image(i,j,1),test_image(i,j,2),test_image(i,j,3)];
end
end
Here cell_data is a cell array having R,G,B color values of individual pixel, whereas cell element indices represent the indices of the pixel itself.
  11 comentarios
Sang
Sang el 26 de Oct. de 2022
what I mean now is to include that image in the matrix color range above
Stephen23
Stephen23 el 30 de Oct. de 2022
Editada: Stephen23 el 30 de Oct. de 2022
Do not use such a complex, inefficient, indirect, insecure, slow, obfuscated approach for accessing the fields of HANDLES. You do NOT need to call evil EVAL, when you can simply use the syntax shown here:
For example, replace this anti-pattern code:
color = eval(sprintf('get(handles.%s,''String'')',current));
with this neat, simple, and very efficient code:
color = get(handles.(current),'String');
Tip for the future: if you find yourself using EVAL (120 times!) just to do something as simple as accessing your data, then you are doing something wrong.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by