필터 지우기
필터 지우기

Help creating a new matrix with these specifications

조회 수: 2 (최근 30일)
Isaiah Stefan Engle
Isaiah Stefan Engle 2017년 4월 5일
I have an image that uses the imfindcircles function to find circles on an image. Once they are found, their information is stored in the 'circle_info' matrix. I then wanted to crop a 20x20 box around the center of each circle and find the total pixel value in that box (excluding values below .6). This code worked sufficiently except for the fact that the circles that were near the edge of the image would cause an error as the code was unable to subtract more than 10 pixels from the center of the circle. This was easily solved with a simple 'if' statement. The problem is, I discovered for my purposes I need to retain the index of those circles. When I use the code below I get a 618x2 matrix that includes [Totalpixelvalue, index_of_circle). The problem is that there is 625 circles in the image I am dealing with which means 7 of those circles are too close to the edge. I need to retain those indexes and include them in the same matrix in the correct order.
For example, the code below will give an example output of
[43.654, 1]
[49.874, 2]
[ 0 , 3]
[ 0 , 4]
[45,553, 5]
Though, what I want is the code to include the missing circles that are too close to the edge (it is fine if their TotalPixelValue is also set to 0, I just need the indexes in the correct order) so the output above should actually be shifted to include the missing index, for example,
[0, 1]
[43.654, 2]
[49.874, 3]
[ 0 , 4]
[ 0 , 5]
[45,553, 6]
I have no idea how to do this. I am very new to matlab. Thank you to anyone who can point me in the right direction.
if true
circle_info = [centers, radii];
[Iy, Ix] = size(I);
[n,~] = size(circle_info); % determine the number of circles contained in circle_info
xcenter = circle_info(:,1); % vector containing x-coordinate of circle centers
ycenter = circle_info(:,2); % vector containing y-coordinate of circle centers
radius = circle_info(:,3); % vector containing radii of centers
TotalPixelValue = [];
for i = 1:(n) % iterate over all circles
if (centers(i,2) > 10)&&(centers(i,1) > 10) && (centers(i,2) < Iy-10) && (centers(i,1) < Ix-10)
cropped = I(int16(centers(i,2)-10) : int16(centers(i,2)+10), int16(centers(i,1)-10) : int16(centers(i,1)+10));
cropped(cropped > .6) = 0;
TotalPixelValue = [TotalPixelValue; [sum(sum(cropped)) i]];
end
end
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by