Cellular Automata with multiple colours as cells.

I need to create cellular automata for an RGB array in MATLAB. Has to be matlab. How can I make cellular rules that are different for a specific coloured cell?
I've attempted code where it takes multiple functions and applies that function to each cell in my array.
function [gameBoard] = myCellularAutomata(gameBoard)
[R, C, ~] = size(gameBoard);
for k = 1:1000 % iterations of game
tempGameBoard = zeros(size(gameBoard));
updatedCellColour = [];
for r = 1:R
for c = 1:C
[updatedCellColour] = applyRule1(gameBoard, [r c]);
if isempty(updatedCellColour)
[updatedCellColour] = applyRule2(gameBoard, [r c]);
if isempty(updatedCellColour)
% etc.
end
end
% all rules have been applied or we have found one rule that satisfies its conditions
if isempty(updatedCellColour)
tempGameBoard(r,c,:) = updatedCellColour; % or however you plan to do this
end
end
end
gameBoard = tempGameBoard;
end
end
(This is code that someone kindly helped me out with, but it unfortunately does not work, either that, or i dont understand it properly)
I expected to recieve cellular automata that applies to the entire array all at once.
(EDIT)
Attached is the image I want to use as my initial array. The plan is to initiate a random walk of red cells onto the grey cells. Over time I want to implement cellular automata rules to the red cells and the cells around it. For instance; if the red cell is next to at least one blue cell, it dies. If a red cell is surrounded by 8 other red cells it dies. I want this simulation to run and stop at my command. I am fully aware on how to run standard 2D cellular automata with a masked (logical) image, but to implement rules for an RGB array is very new to me.
Note: I have a very handy function that alows me to turn any image into a pixelated array that I like, the only problem is is the cellular automata and random walk input. I am very novice when it comes to the style of coding, but am a fast learner. I appreciate any and all feedback.
Thankyou
(EDIT)
I apologise, I don't know hwo to enlarge the image, but if you zoom in, you should get the idea.

5 Comments

It would be helpful to answer the question, if your question have followings two things
  1. What you have, share image or code or data?
  2. What output you are expecting?
In this forum, members are from diverse subjects, therefore dont assume that all members know the all basic terms in your subjects. It would be better if you can elaborate in detail (Mathematical or Image)
Good Wishes!
What do you want as the final output? Can you attach an image of it?
What does gameBoard look like? Can you attach it in a .mat file?
How about if you just used superpixels() or voronoi() to create an image with big, irregularly-shaped, uniformly colored regions?
Thankyou, I'm sorry, I was quite a bit vague. I have edited and updated my question. Hopefully this makes it clearer. Thankyou greatly for answering!
This question has updated info, and I hoped reposting a question would attract more help.

Sign in to comment.

Answers (0)

Categories

Find more on Just for fun in Help Center and File Exchange

Products

Asked:

on 25 May 2019

Commented:

on 26 May 2019

Community Treasure Hunt

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

Start Hunting!