Effacer les filtres
Effacer les filtres

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 vues (au cours des 30 derniers jours)
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

Réponses (1)

Image Analyst
Image Analyst le 20 Avr 2013
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?
  2 commentaires
Ralph Dunne
Ralph Dunne le 20 Avr 2013
I am trying to complete the algorithm on pg 2,3 & 4 of this document http://www.cvmt.dk/education/teaching/f10/MED8/CV/Stud/835.pdf
The nhood and surrounds are the same, they are the 8 surrounding pixels of the current pixel the for loop is on. I separated them as I was including extra pixels in nhood to try something.
Transition represent the number of 0 to 1 changes that occur in the nhood rotating clockwise beginning at the pixel above the one the loop is on.
the link provided explains the IF statement, it is very short and can be read quickly. It is Gonzales and Woods technique to take the skeleton from an image. the image being used is one I created that is binary and simply states the word skeleton in white against a black backgorund

Connectez-vous pour commenter.

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by