I have an image that consists of concentric circles. How do I traverse each circle separately (knowing the Center coordinates and radius) in MATLAB?
if I think I understand the question correctly you are looking for a circle around a given point on an image. I have posted some code below, that will retrieve these points for you.
im = zeros([50,50]);
center = [20,20];
radius = 5;
x = 1:size(im,1);
y = 1:size(im,2);
[xx,yy] = meshgrid(x-center(1),y-center(2));
dist = sqrt(xx.^2+yy.^2)
circle = dist > radius-1 & dist < radius+1;
im would just be whatever the image is your are looking at
Related
Simplifying the question. I want to find the relevant position of an ROI to other ROIs and place the results in a matrix.
example, here is a picture containing a series of ROIs.
Positions of ROIs can be pulled using the region props function.
stats = regionprops(ROIs,'centroid');
First I thought of taking a centroid and using it as an anchor for other points
t1 = transpose([stats.Centroid]);
t2 = transpose(reshape(t1,[2,40]));
[~,idx] = find(t2(:,1)==min(t2(:,1)));
anchorpoint = t2(idx,:);
ydif = t2(:,1)-anchorpoint(1);
xdif = t2(:,2)-anchorpoint(2);
This will give me relative distances to the anchor point with sign (+ -) denoting before, after or above, below. what would be the next step?
I can find the supposed dimensions of the array from the anchor point
ydim = sum((abs(ydif)<20))
ydim = 5
xdim = sum((abs(xdif)<20))
xdim = 8
but this is relative as there are gaps in ROIs.
I'm an lost as to what to do from this point
I currently have to create a sphere from a stack of 2D slices (2D matrices in MATLAB, which represent 2D gray scale images). I have created a bunch of slices using the code below. To create the sphere I have repeatedly created slices of circles of increasing size till 100, and then of decreasing sizes. All of these slices are added to a 3D matrix.
Circle = ones(200,400,400);
for i = 1:100
[rr cc] = meshgrid(1:400);
C = sqrt((rr-200).^2+(cc-200).^2)<=i;
for j = 1:400
for k = 1:400
Circle(i,j,k) = C(j,k);
end
end
end
index = 100;
for i = 1:100
[rr cc] = meshgrid(1:400);
C = sqrt((rr-200).^2+(cc-200).^2)<=index;
for j = 1:400
for k = 1:400
Circle(i+100,j,k) = C(j,k);
end
end
index = index - 1;
end
viewer3d(Circle);
viewer3d is 3rd part library that helps you view your 3D image stacks of slices as 3d objects. Once I visualized this 'supposed' sphere, I realized that it is a diamond shape top and not a sphere.
Therefore I do not understand how to vary the size of circles till the center point of the sphere in the y plane and then decrease it with the same algorithm.
Thank you for your answers and please do not hesitate to ask me to clarify anything within this question.
Alternatively, create a sphere directly, without using loops:
Circle = zeros(200,400,400);
[x,y,z]=meshgrid(1:size(Circle,1),1:size(Circle,2),1:size(Circle,3));
radius=??; %// e.g. radius=100;
%//this sphere is centered in the middle of the image
Circle(sqrt((x-size(Circle,1)/2).^2+(y-size(Circle,2)/2).^2..
+(z-size(Circle,2)/2).^2)<radius)=1;
Yes, the radius along the Z axis is not linear but varies with cos/sin function. Using this representation:
your radius is "Radius = r sin(Theta)", with "Theta = arccos(r / z)". So "r" is the radius of your sphere, and "z" the level/slice you want to draw in. Don't forget to that "z" goes from -"r" to "r". I've tested the formulae and it works fine for an image stack (slices).
I have a list of coordinates, which are generated from another program, and I have an image.
I'd like to load those coordinates (making circular regions of interest (ROIs) with a diameter of 3 pixels) onto my image, and extract the intensity of those pixels.
I can load/impose the coordinates on to the image by using;
imshow(file);
hold on
scatter(xCoords, yCoords, 'g')
But can not extract the intensity.
Can you guys point me in the right direction?
I am not sure what you mean by a circle with 3 pixels diameter since you are in a square grid (as mentioned by Ander Biguri). But you could use fspecial to create a disk filter and then normalize. Something like this:
r = 1.5; % for diameter = 3
h = fspecial('disk', r);
h = h/h(ceil(r),ceil(r));
You can use it as a mask to get the intensities at the given region of the image.
im = imread(file);
ROI = im(xCoord-1:xCoord+1; yCoord-1:yCoord+1);
I = ROI.*h;
Just a quick question. I've an image and I've extracted a certain point (feature), I know the coordinates of that point in every frame.
Say x1 and y1.
I need a circular ROI form that point on the image with a radius that I chose.
I tried impoly and roipoly - not sure how to use either of these when I know the point in the image.
Thanks
Since you know the coordinates of the center of the ROI along with the radius, you can modify a bit the code provided by #Jonas here to create a circular mask in a quite efficient way.
Example:
clc;clear
Im = imread('coins.png');
[rNum,cNum,~] = size(Im);
%// Define coordinates and radius
x1 = 60;
y1 = 100;
radius = 40;
%// Generate grid with binary mask representing the circle. Credit to Jonas for original code.
[xx,yy] = ndgrid((1:rNum)-y1,(1:cNum)-x1);
mask = (xx.^2 + yy.^2)<radius^2;
%// Mask the original image
Im(mask) = uint8(0);
imshow(Im)
Output:
EDIT
If you want to see only the outer edge of the ROI to see the center, add a logical condition with some tolerance for the radius of a smaller circle. Something like this:
mask = (xx.^2 + yy.^2)<radius^2 & (xx.^2 + yy.^2)>(radius-tol)^2;
With a tol of 2 it looks like this:
Hello
I have a problem of finding pixel position after imrotate
`img = imread('rice.png');
point = [100;120];
angle = 45;
img_rot = imrotate(img,angle);
new_point ??`
Simple way: Apply the same transformation to a image with a single dot:
s=size(img);
marker=zeros(s(1:2));
marker(point(1),point(2))=1;
marker_rot = imrotate(marker,angle);
[x,y]=find(marker_rot)