Azzera filtri
Azzera filtri

polygon edge exclusion using circles and logical arrays

3 visualizzazioni (ultimi 30 giorni)
Hello,
I'm working on a program that would allow me to remove the pixels in an image around the edge of a polygon. I chose to use logical arrays and assign 0 and 1 to all pixels that I'd like to remove and keep, respectively.
I am able to find the edge of the polygon succesfully- edge coordinates are in first(). Next I drew circles of constant radius centered around each pixel and assign all values in the circles to 0. I am trying to use a "for loop" to go through the coordinates of all pixels on the polygon edge and repeat the process. I expect the result to be a logical cell of size w by h_t (844 by 844) that has 0 around the edge and the circles around it and 1 elsewhere. The problem that I have is storing the data: I try to use a cell array C and have each iteration saved such that iteration 5 would be in C{5} and so on. Then I apply logical xor to all in a loop an obtain the final array. In current form the program only has one circlePixels array not 844, or size(first,1). I might be missing something obvious-please help.
I use R2019b Update 4 with Image Proc Toolbox (11.0).
% first is an array with edge coordinates-844 pairs (uint16)
% Create a logical image of a circle with specified radius, center, and image size.
% Radius is 40.
% First create the image and the center arrays.
[columnsInImage rowsInImage] = meshgrid(w, h_t);
centerX=zeros(1,size(first,1)); % size determined by size of first edge array
centerY=zeros(1,size(first,1));
for i=1:size(first,1)
centerX(i)=first(i,1);
centerY(i)=first(i,2);
circlePixels= (rowsInImage - centerX(i)).^2 ... % circlePixels is a 2D "logical" array.
+ (columnsInImage - centerY(i)).^2 <= radius.^2;
C{i}=circlePixels; % each iteration store circlePixels logical array in C
end
% C has one row of zeros
% add all circles in an image
summ_circles=C{1};
for k=1:size(C,2)
summ_circles=xor(summ_circles,C{k});
end
imagesc(summ_circles)

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by