Search code examples
matlabimage-processingresolution

How do i create images with specified resolution?


I want to create an image with resolution of 56 pixels/diameter (with varying diameters of say: 50, 100, and 150 pixels), by first specifying its height and width and then using the meshgrid function to digitize the image (see example code below). Secondly, how do i increase the resolution by a factor of 2 (say: 112, and 224 pixels/diameter)?

Example:

RowSize = 400;
ColSize = 400;

[gridRow, gridCol] = meshgrid(1:RowSize, 1:ColSize);

%specify the diameter
d = 100;

% create the image
I       = (gridRow - 200).^2 + (gridCol - 200).^2 <= (d/2).^2;
figure, imshow(I, []);

The main issue I will think is how to determine the Row and Col sizes such that I have the desired resolutions.

Please any help/suggestions is greatly appreciated. Thank you!


Solution

  • I think this is what you are after:

    %specify the diameter
    d = 100;
    
    RowSize = d;
    ColSize = d;
    
    %Subtract 0.5 to get the center correclty
    [gridRow, gridCol] = meshgrid((1:RowSize)-0.5, (1:ColSize)-0.5);
    
    % create the image
    I = (gridRow - d/2).^2 + (gridCol - d/2).^2 <= (d/2).^2;
    figure, imshow(I, []);
    

    Result:
    enter image description here