1

我随机生成了遗传算法的初始 10 个种群(每个大小为 n),如下所示

for i = 1:10
    for j=1:n
        population(i,j)=randi([MinIntensity,MaxIntensity]);
    end
end

假设我有一个人口的值。例如,让第一个大小为 10 的人口是 [100 110 120 130 140 150 160 170 180 190]。是否可以生成剩余的 9 个人口,使得值接近第一个种群?(这是为了遗传算法的快速收敛)。此外,每个种群都是灰度图像,其强度值以行主要顺序表示。因此强度值应在 0 - 255 的范围内。请帮助。谢谢进步

4

1 回答 1

2

You can do one thing. Use the first string as it is for the rest of the 9 strings except randomly generate an index (between 1 to n) and assign a random integer only to that positions with that random index.

population(1,:) = [100 110 120 130 140 150 160 170 180 190];

for i = 2:10
    idx = randi([1 10]);
    population(i,:) = population(1,:);
    population(i,idx) = randi([0 255]);
end

With this you will get ten strings differing in only one position.

Edit: Image. Assuming you have a MXN image. Create a mask for example

randi([-10 10], M , N)

Now add this to your original image. Now you get a new image whose all the pixels are modified but only within the range of -10 to 10. Some of the pixel values might go out of range in that case just modify as below

 x(find(x < 0)) = 0 %Here X is your new image.

 x(find(x > 255)) = 255
于 2015-04-10T09:09:03.847 回答