Random black and white pixels forming clusters, input proportion of white
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
My knowledge of Matlab is very (very) limited but I am trying to find a code for the following: let's say on a 10*10 image, I would like to be able to enter the porportion of black and white pixels, and generate random images (for instance, generate many random images that are 50% black). The thing is it shouldn't only be pixels, but these should form clusters. One idea would be to define a few random points on the image (five on the example below, at random positions of the 10*10 image). These points would be black and the rest of the image white, so to start. Then around the points, progressively decrease the probability of having a black pixel (this is what I tried to represent with circles around the first point). In the end, it would form clusters and we could give the proportion of white (or black) pixels as an input (e.g. generate random images 50% black). Any help for finding such a code is more than welcome.
I hope this makes sense, please don't hesitate to ask for clarifications. Many thanks in advance for your help.
댓글 수: 0
답변 (2개)
harjeet singh
2015년 12월 27일
hello lucy do use this code
clear all
close all
warning off
clc
initial_dots=5;
a=500;
img(1:a,1:a)=1;
img=logical(img);
figure(1)
imshow(img)
drawnow
pos=randint(initial_dots,2,[1 a]);
for i=1:length(pos)
img(pos(i,1),pos(i,2))=0;
end
figure(2)
imshow(img)
drawnow
for i=1:5
for k=1:20
theta=0:k:360;
r=round(pos(i,1) + k*sin(theta));
c=round(pos(i,2) + k*cos(theta));
for j=1:length(r)
if(r(j)>0 && r(j)<a && c(j)>0 && c(j)<a)
img(r(j),c(j))=0;
end
end
end
end
figure(3)
imshow(img)
drawnow
댓글 수: 1
Image Analyst
2015년 12월 27일
Good start. What toolbox is randint() in? Can you make it work with the built-in randi() instead? Can you make it work with randomness so that you are not just plopping down a point with 100% certainty? How are you keeping track of the number of points drawn so as to achieve the desired % blackness?
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!