I am running a for loop on a binary image, as I flag a pixel I would like to store this pixels location (x,y) in a variable that will collect all the flag points locs so I can alter them after the for loop is completed?? is there a matlab function?
2 ビュー (過去 30 日間)
古いコメントを表示
the line I need help with is contained in the if statement within the nested for loop "[C,I] = find(I == (I(i,j)))" I need a line of code that when the four conditions of the IF statement are valid then this line will collect the flagged points location(x,y) and store it along with all other flagged pixels in a variable so I can alter them after the nested for loops are completed
clear all I=imread('skeleton.jpg'); I = im2double(I); %change from unit 8 to double I = im2bw(I);
figure, imshow(I);
H = size(I, 1); %height of image
W = size(I, 2); %width of image
for i = 2:H-1
for j = 2:W-1
nhood = [I(i-1,j) I(i-1,j+1) I(i,j+1) I(i+1,j+1) I(i+1,j) I(i+1,j-1) I(i,j-1) I(i-1,j-1)];
surrounds = [I(i-1,j) I(i-1,j+1) I(i,j+1) I(i+1,j+1) I(i+1,j) I(i+1,j-1) I(i,j-1) I(i-1,j-1)];
Transition = nnz(diff(surrounds)==1);
Non_zero = sum(nhood(:)==1);
if Transition==1 && (2<=Non_zero<=6) && (I(i-1,j)*I(i,j+1)*I(i+1,j)==0) && (I(i,j+1)*I(i+1,j)*I(i,j-1)==0)
**** *[C,I] = find(I == (I(i,j)));*****
else I(i,j)=I(i,j);
end
end
end
0 件のコメント
回答 (1 件)
Image Analyst
2013 年 4 月 20 日
Whatever you're doing, it looks horribly inefficient. I'm sure you could do it with conv2() much faster and much more efficiently. Your nhood and surrounds look like the same arrays. Please explain in words what this code is doing. What does Transition represent? What are the 4 conditions the if statement is checking for? Can you put in some comments and give us a binary pattern which "triggers" the if statement?
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!