Ship like objects in 2D
For reference see incontrastsRef.html.
Contents
Description
This contrast shows a kind of sailing ship in the real part and a kind of submarine in the imaginary part.
Example
Visualize the real and imaginary part of this contrast:
seti.contrast = 'ship2D'; seti = setGeomSim(seti); figure(1); imagesc(real(seti.G(seti.qROIexact))); axis xy; colorbar; figure(2); imagesc(imag(seti.G(seti.qROIexact))); axis xy; colorbar;
More About
Sailing ship in real part:
- Thick horiozontal rectangle: gradual contrast ramp (from ~0.23 to ~1.28) (hull of ship)
- Small squares and big square: q = 0.5.
- Leftover objects: q = 1.
- Submarine in imaginary part:
- Same thick horizontal rectangle as in real part, but at another position and with gradual contrast ramp in imaginary part.
- Big square on top with q = i.
- Small squares: q = 0.5i.
Notes
- The origin (0,0) is in the center of the ROI.
- The squares are really squares and equidistant distributed, although it does not look like if the grid resolution is low.
small squares: 1st row (left): real(q) is negative (-0.2) 2nd row: imag(q) = 0.5 3rd row: imag(q) = 0.25 4th row: imag(q) should be clear.
Code
function q = ship2D(X1,X2,varargin)
seti = varargin{end}; R = seti.rCD/2; n = sqrt(length(X1)); % n = nCD or nROI % New layer... (for gradual contrast ramp: left high, right low...) lspace = linspace(1,0,n); % values between 1 and 0 L = repmat(lspace,[n 1]); % L is a matrix... but we need a vector... L = reshape(L,[1 n^2]); L = 1.5.*L; % new L is between 0 and 1.5 % q = L.*rect(-4/8,4/8,-2/8,-1/8, X1,X2,R); % unique(q) % only with real numbers; see second ans: 0, 0.2333, ..., 1.2833
Sailing Ship (real part) and Submarine (imaginary part)
% Rectangles of Sailing Ship: q = 0; q = q + L.*rect(-4/8,4/8,-1/8-1/16,-1/8, X1,X2,R); % thick horizontal line (but not so thick) % Rotate thin line in front of the ship: [X1rot,X2rot] = gridRot(25,X1,X2); % rotate the grid q = q + rect(3/8,3/8+1/32,-1/8-1/16,3/8, X1rot,X2rot,R); % thin line (will be rotated because of X1rot, X2rot) % Small Squares (real and imaginary): a = [0.5, 0.5+1i*0.5, 0.5+1i*0.25, -0.1]; % contrast value of small squares for i = 1:4 % squares (last column) q = q + a(i).*rect(0/16,1/16,(2*i-1)/16,(2*i)/16, X1,X2,R); % square end for i = 1:3 % squares q = q + a(i).*rect(-2/16,-1/16,(2*i-1)/16,(2*i)/16, X1,X2,R); % square end for i = 1:2 % squares q = q + a(i).*rect(-4/16,-3/16,(2*i-1)/16,(2*i)/16, X1,X2,R); % square end for i = 1:1 % squares q = q + a(i).*rect(-6/16,-5/16,(2*i-1)/16,(2*i)/16, X1,X2,R); % square end % Circles (real and imaginary): q = q + circle(3/8+1/16,4/8+1/16+1/32,1/16, X1,X2,R); % top right q = q + 1i.*circle(-3/8-1/16,4/8+1/16+1/32,1/16, X1,X2,R); % circle top left % Submarine (rectangles): q = q+1i.*L.*rect(-4/8,4/8,-4/8-1/16,-4/8, X1,X2,R); % thick horizontal line (but not so thick) q = q + 1i.*rect(1/8,1/8+1/16,-4/8,-4/8+1/16, X1,X2,R); % square on top (but not so thick)
q = double(q);
end
Code: subfunction: rect
function q = rect(x1,x2,y1,y2,X1,X2,R) % rectangle % % Description: % rect is a rectangle with points A = (x1,y1) and B = (x2,y2). % % Input: % x1,y1 : First point (x1,y1) % x2,y2 : Second point (x2,y2) % X1, X2 : Grid % R : Scaling factor R = seti.rCD/2 q = (x1*R <= X1) & (X1 < x2*R) & (y1*R <= X2) & (X2 < y2*R); end
Code: subfunction: circle
function q = circle(x,y,r, X1,X2,R) % filled circle % Input: % x, y : Postion (x,y) % r : Radius of the circle. q = ((X1-x*R).^2 + (X2-y*R).^2 <= (r*R)^2); % ball end
Code: subfunction: gridRot
Similar to the subfunction rotateGrid in setContrast, but for rotation of a single object and using X1, X2.
Input Arguments
- alphaDeg : Rotation angle alpha in degrees.
- X1 : 1st components of grid (like X1 = seti.gridROI(1,:))
- X2 : 2nd components of grid (like X2 = seti.gridROI(2,:))
- Output Arguments*
- X1rot, X2rot : Rotated X1 and X2.
function [X1rot,X2rot] = gridRot(alphaDeg,X1,X2) % Rotation matrix in R^2 R = @(alpha) [cos(alpha), -sin(alpha); sin(alpha), cos(alpha)]; % Compute alpha in rad and set minus % such that seti.rotation is mathematical positive rotation in degrees. alpha = -alphaDeg/360*2*pi; gridRotated = R(alpha)*[X1; X2]; X1rot = gridRotated(1,:); X2rot = gridRotated(2,:); end