Select pixels from a matrix given the centers ?
Ältere Kommentare anzeigen
Suppose we have a given matrix (I) and a structure containing some centers of the matrix before.
For example:

In this case, I is a 9x9 matrix and we have the centers: a22, a63, a45, a26. Normally the number of centers is a square number.
Suppose we want to select all the pixels far from the centers of +1 position on the rows and +3 positions on the columns
The new matrix (A) will be:

My code is:
for c = 1:n
for r = 1:n
uno=Struttu.x(c + ( (r-1) * n));
due=Struttu.y(c + ( (r-1) * n));
A(r,c) = (I( uno +3 , due +1));
end
end
where n*n is the total number of centers.
This code works fine, but is there a faster way to implement it?
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 26 Mär. 2023
0 Stimmen
Yes, you can use meshgrid. Code is in the FAQ: https://matlab.fandom.com/wiki/FAQ#How_do_I_create_a_circle?
Your x and y have to be column and row indexes of course.
Let me know if you can't figure it out.
4 Kommentare
MementoMori
am 26 Mär. 2023
Image Analyst
am 26 Mär. 2023
So do you want a list of all pixels in an ellipse 6 pixels wide and 2 pixels tall? Or do you want a rectangular matrix of all those inside the box, like
inBox = m(row-1:row+1, col-3 : col+3); % Rectangular matrix
MementoMori
am 28 Mär. 2023
Image Analyst
am 28 Mär. 2023
Bearbeitet: Image Analyst
am 28 Mär. 2023
centerRow = ceil(size(m, 1)/2);
centerCol = ceil(size(m, 2)/2);
youWant = m(centerRow + 3, centerCol + 1)
To learn other fundamental concepts, invest 2 hours of your time here:

Kategorien
Mehr zu Line Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
