How can I randomly choose a neighbouring pixel from an Image..
이전 댓글 표시
Hello Every one
How can I randomly choose the pixels value from an image.Any help is appreciated.
Thanks
채택된 답변
추가 답변 (1개)
Walter Roberson
2013년 6월 22일
switch randi(8,1,1)
case 1: rpix = YourImage(i-1,j-1);
case 2: rpix = YourImage(i-1,j);
case 3: rpix = YourImage(i-1,j+1);
case 4: rpix = YourImage(i,j-1);
case 5: rpix = YourImage(i,j+1); %skip i,j as that is the pixel itself
case 6: rpix = YourImage(i+1,j-1);
case 7: rpix = YourImage(i+1,j);
case 8: rpix = YourImage(i+1,j+1);
end
댓글 수: 6
Algorithms Analyst
2013년 6월 22일
편집: Walter Roberson
2013년 6월 22일
Walter Roberson
2013년 6월 22일
You would need to use RPIX(i,j) instead of RPIX(i'j)
The code you show should work, but it will not choose a neighbor at random.
Algorithms Analyst
2013년 6월 22일
Walter Roberson
2013년 6월 22일
Img = imread('g.bmp');
Rpix = zeros(size(img));
[m n] = size(img)
for i = 2:m-1
for j = 2:n-1
switch randi(8,1,1)
case 1: rpix = YourImage(i-1,j-1);
case 2: rpix = YourImage(i-1,j);
case 3: rpix = YourImage(i-1,j+1);
case 4: rpix = YourImage(i,j-1);
case 5: rpix = YourImage(i,j+1); %skip i,j as that is the pixel itself
case 6: rpix = YourImage(i+1,j-1);
case 7: rpix = YourImage(i+1,j);
case 8: rpix = YourImage(i+1,j+1);
end
RPIX(i,j) = rpix;
end
end
Caution: the code would need to be changed if g.bmp is an RGB image.
Algorithms Analyst
2013년 6월 27일
GOVARDHAN
2014년 4월 21일
Delete colon from ur code and run it.
clc close all clear all img = imread('brain1.jpg'); img=rgb2gray(img); Rpix = zeros(size(img)); [m n] = size(img); for i = 2:m-1 for j = 2:n-1 switch (randi(8,1,1)) case 1 rpix =img(i-1,j-1); case 2 rpix =img(i-1,j); case 3 rpix = img(i-1,j+1); case 4 rpix = img(i,j-1); case 5 rpix = img(i,j+1); %skip i,j as that is the pixel itself case 6 rpix = img(i+1,j-1); case 7 rpix = img(i+1,j); case 8 rpix = img(i+1,j+1); end Rpix(i,j) = rpix end
카테고리
도움말 센터 및 File Exchange에서 Image Arithmetic에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!