problem with cellular automata code?

2 Ansichten (letzte 30 Tage)
sara
sara am 21 Okt. 2014
Kommentiert: Geoff Hayes am 23 Feb. 2016
i found this code here, and i try to initialize it with [1 0 1 1 0 1 1] but it didn't work.
the code is long to paste it here. and how to locate the image?

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 21 Okt. 2014
Sara - how did you try to execute the code? Based on the given link, the function requires a rule (so this is an integer from 1 to 255), an optional initial state, and an optional number of rows (iterations for the cellular automata). What is your [1 0 1 1 0 1 1] - a rule or an initial state?
For example, the command
wolfram(45)
creates an interesting image, as does some of the other examples included in the comments (from the rich vector).
If your vector is an initial state, then you would specify the rule (1-255) and supply the state vector
wolfram(45, [1 0 1 1 0 1 1], 50);
Note that since your initial state is narrow (only 7 columns) then the number of rows should be kept small too else the image will be difficult to view.
  15 Kommentare
cathrin philo
cathrin philo am 22 Feb. 2016
Bearbeitet: Geoff Hayes am 23 Feb. 2016
thank you for your response.
if nargin < 300, nrows=221; end
if nargin < 300 %Use default initial state
ncols=228; A=zeros(nrows,ncols); A(1,ncols-1)=1;
else
[unused, ncols]=size(initialstate)
A=zeros(nrows, ncols); A(1,:)=initialstate;
end
rule=dec2bin(wolfrule,8);
where i have changed row=221;col=228. i don't know whether the output is for my input image or not? how can i procced with?
Geoff Hayes
Geoff Hayes am 23 Feb. 2016
cathrin - you will need to update the wolfram function to return the output A as
function [A] = wolfram(wolfrule, initialstate, grows)
As for changing the nrows and ncols, why have you chosen 221 and 228? Are these the dimensions of your original image? Because I would think that you wouldn't have to modify these numbers at all. For example, suppose you wish to apply to the 40th row of your image which is a 256x512 image. Then you would call wolfram as
A = wolfram(150,myImg(40,:),256-40+1);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by