How can I find random pixels in an image?

조회 수: 5 (최근 30일)
Faranak
Faranak 2014년 2월 13일
댓글: Image Analyst 2014년 2월 13일
Hi all, I have a 256*256 pixels image and I want to have 5 randomly pixels in it.how can I do that?
  댓글 수: 1
Faranak
Faranak 2014년 2월 13일
I have some pixels with value more than 1 , I want to find randomly from those pixels. I tried this command : randi(size(imfinal),1,5) but it gives me random number of pixel number. I want exactly the number of i , j of the pixel,and those pixel which their value is more than 1 .

댓글을 달려면 로그인하십시오.

채택된 답변

Faranak
Faranak 2014년 2월 13일
I found the answer,for those who want it:
%%% imfinal is the image
for i=1:256 for j=1:256 if imfinal(i,j)>2 f=imfinal;
end
end
end
%%%% 1800 is the total number of pixels with value more than 1
fo=find(f>20); rndm=randi(1800,1,5); fo2=fo(rndm);
  댓글 수: 1
Image Analyst
Image Analyst 2014년 2월 13일
That does not do what you asked. The first loop merely assigns the entire image to f. The second part looks at only the first 1800 pixels with a value of more than 20 and picks the linear index of 5 of them.
It doesn't give you "number of i , j of the pixel" and doesn't look at "those pixel which their value is more than 1". But whatever...as long as you're happy.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by