how to divise an image with matrix rotation(same angle)
1 view (last 30 days)
Show older comments
i want to divise my image into 6 segments with the same angle(theta=60),this code didn't give me the right result i want(it shows me an angle<60),am waiting for ur help .My code :
I=imread('D:\IRM\image_amplitude_final.png');
figure(1),
imshow(I,[]);
impixelinfo;
x(1) = input('Give the centre X coord : '); % X coord
x(2) = input('Give the centre y coord : '); % y coord
y(1) = input('Give x coord : ');
y(2) = input('Give y coord : ');
line ([x(1) y(1)],[x(2) y(2)],'LineWidth',1,'color','w')
v = [x;y];
x_center = x(2);
y_center = y(2);
center = repmat([x_center; y_center], 1, length(x));
theta = 60;
R = [cosd(theta) -sind(theta) ; sind(theta) cosd(theta)];
s = v - center;
so = R*s;
vo = so + center;
x_rotated = vo(1,:)
y_rotated = vo(2,:)
line([x(1) x_rotated(1)],[x(2) x_rotated(2)],'LineWidth',1,'color','w')
hold on
v = [x;y];
x_center = x(2);
y_center = y(2);
center = repmat([x_center; y_center], 1, length(x));
theta = 60;
R = [cosd(theta) -sind(theta); sind(theta) cosd(theta)];
R = [cosd(theta) -sind(theta) 0; sind(theta) cosd(theta) 0; 0 0 1];
s = v - center;
so = R*s;
vo = so + center;
x1_rotated = vo(1,:)
y1_rotated = vo(2,:)
line ([x(1) x1_rotated(1)],[x(2) x1_rotated(2)],'LineWidth',2,'color','w')
0 Comments
Answers (1)
DGM
on 25 Aug 2023
Edited: DGM
on 25 Aug 2023
I was going to fix the code. This is how it went:
% okay, get some single-channel image
I = imread('cameraman.tif');
imshow(I,[]);
impixelinfo;
% it's totally unclear what's being requested here
% the inputs for x and y are not consistently stored in the corresponding variable
% harassing the user to enter the same parameters manually every single
% time is maddening, slow, error-prone, and totally unnecessary
% x(1) = input('Give the centre X coord : '); % X coord << if this is "x coord"
% x(2) = input('Give the centre y coord : '); % y coord
% y(1) = input('Give x coord : '); % << then what is this? x coord of _what_??
% y(2) = input('Give y coord : ');
% if you want a script, just enter the parameters _in the script_
% if you want a function, take the parameters _as arguments_
x = [32 1];
y = [128 1];
% it seems that the concept of x and y are indeed being abused
line([x(1) y(1)],[x(2) y(2)],'LineWidth',1,'color','r')
% if i have to second guess whether or when x means y
% it's going to be difficult to debug or guess intent
... at which point I gave up.
If all you need was to draw lines over a displayed image, you could simply do:
% image to display
inpict = imread('cameraman.tif');
% parameters
cen = [80 128]; % center point [x y]
dpt = [192 64]; % datum point [x y]
nslices = 6; % number of slices/segments
% generate point list from a vector of angles
pt0 = dpt-cen;
theta = linspace(0,360,nslices+1) + atan2d(pt0(2),pt0(1));
r = norm(pt0);
x(2,:) = r*cosd(theta(1:end-1));
y(2,:) = r*sind(theta(1:end-1));
x = x + cen(1);
y = y + cen(2);
% display the image, reference points, and lines
imshow(inpict); hold on
plot(cen(1),cen(2),'yo','linewidth',2)
plot(dpt(1),dpt(2),'yo','linewidth',2)
plot(x,y,'c')
... but drawing lines in a figure doesn't really seem to address what the question was asking for.
This thread covers a similar problem:
... though with the intent being unclear here, it's hard to say how much overlap there is.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!