Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I believe this is typically referred to as either a "fisheye lens" effect or a "barrel transformation". Here are two links to demos that I found:</p> <ul> <li><p><a href="http://www.mathworks.com/matlabcentral/answers/98431-is-there-more-information-available-on-using-the-custom-option-with-the-maketform-function-in-the" rel="nofollow noreferrer">Sample code</a> for how you can apply fisheye distortions to images using the <code>'custom'</code> option for the function <a href="https://www.mathworks.com/help/images/ref/maketform.html" rel="nofollow noreferrer"><code>maketform</code></a> from the <a href="https://www.mathworks.com/help/images/index.html" rel="nofollow noreferrer">Image Processing Toolbox</a>.</p></li> <li><p><a href="https://www.mathworks.com/help/images/examples/creating-a-gallery-of-transformed-images.html?prodcode=IP&amp;language=en#zmw57dd0e4378" rel="nofollow noreferrer">An image processing demo</a> which performs a barrel transformation using the function <a href="https://www.mathworks.com/help/images/ref/tformarray.html" rel="nofollow noreferrer"><code>tformarray</code></a>.</p></li> </ul> <h2>Example</h2> <p>In this example, I started with the function <code>radial.m</code> from the <a href="http://www.mathworks.com/matlabcentral/answers/98431-is-there-more-information-available-on-using-the-custom-option-with-the-maketform-function-in-the" rel="nofollow noreferrer">first link above</a> and modified the way it relates points between the input and output spaces to create a nice circular image. The new function <code>fisheye_inverse</code> is given below, and it should be placed in a folder on your <a href="https://www.mathworks.com/help/matlab/ref/path.html" rel="nofollow noreferrer">MATLAB path</a> so you can use it later in this example:</p> <pre><code>function U = fisheye_inverse(X, T) imageSize = T.tdata(1:2); exponent = T.tdata(3); origin = (imageSize+1)./2; scale = imageSize./2; x = (X(:, 1)-origin(1))/scale(1); y = (X(:, 2)-origin(2))/scale(2); R = sqrt(x.^2+y.^2); theta = atan2(y, x); cornerScale = min(abs(1./sin(theta)), abs(1./cos(theta))); cornerScale(R &lt; 1) = 1; R = cornerScale.*R.^exponent; x = scale(1).*R.*cos(theta)+origin(1); y = scale(2).*R.*sin(theta)+origin(2); U = [x y]; end </code></pre> <p>The fisheye distortion looks best when applied to square images, so you will want to make your images square by either cropping them or padding them with some color. Since the transformation of the image will not look right for <a href="https://www.mathworks.com/help/images/image-types-in-the-toolbox.html#f14-17587" rel="nofollow noreferrer">indexed images</a>, you will also want to convert any indexed images to <a href="https://www.mathworks.com/help/images/image-types-in-the-toolbox.html#f14-20224" rel="nofollow noreferrer">RGB images</a> using <a href="https://www.mathworks.com/help/matlab/ref/ind2rgb.html" rel="nofollow noreferrer"><code>ind2rgb</code></a>. <a href="https://www.mathworks.com/help/images/image-types-in-the-toolbox.html#f14-13941" rel="nofollow noreferrer">Grayscale</a> or <a href="https://www.mathworks.com/help/images/image-types-in-the-toolbox.html#f14-33397" rel="nofollow noreferrer">binary images</a> will also work fine. Here's how to do this for your sample <a href="http://www.google.com/intl/en_ALL/images/srpr/logo1w.png" rel="nofollow noreferrer">Google logo</a>:</p> <pre><code>[X, map] = imread('logo1w.png'); % Read the indexed image rgbImage = ind2rgb(X, map); % Convert to an RGB image [r, c, d] = size(rgbImage); % Get the image dimensions nPad = (c-r)/2; % The number of padding rows rgbImage = cat(1, ones(nPad, c, 3), rgbImage, ones(nPad, c, 3)); % Pad with white </code></pre> <p>Now we can create the transform with <a href="https://www.mathworks.com/help/images/ref/maketform.html" rel="nofollow noreferrer"><code>maketform</code></a> and apply it with <a href="https://www.mathworks.com/help/images/ref/imtransform.html" rel="nofollow noreferrer"><code>imtransform</code></a> (or <a href="https://www.mathworks.com/help/images/ref/imwarp.html" rel="nofollow noreferrer"><code>imwarp</code></a> as recommended in newer versions):</p> <pre><code>options = [c c 3]; % An array containing the columns, rows, and exponent tf = maketform('custom', 2, 2, [], ... % Make the transformation structure @fisheye_inverse, options); newImage = imtransform(rgbImage, tf); % Transform the image imshow(newImage); % Display the image </code></pre> <p>And here's the image you should see:</p> <p><a href="https://i.stack.imgur.com/dXgtK.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dXgtK.jpg" alt="enter image description here"></a></p> <p>You can adjust the degree of distortion by changing the third value in the <code>options</code> array, which is the exponential power used in the radial deformation of the image points.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload