Using MATLAB for Basic Image Editing


MATLAB provides a wide range of tools for basic image editing, allowing you to perform operations like resizing, cropping, adjusting brightness, and more. In this guide, we'll introduce you to basic image editing in MATLAB with sample code and examples.

Loading an Image

You can load an image into MATLAB using the imread function. Images can be in various formats such as JPEG, PNG, or BMP.

% Example: Loading an image
img = imread('sample.jpg');

Displaying an Image

You can display an image using the imshow function to visualize the loaded image.

% Example: Displaying an image

Resizing an Image

To resize an image, you can use the imresize function and specify the desired dimensions.

% Example: Resizing an image
resized_img = imresize(img, [300, 400]);

Cropping an Image

You can crop an image to a specific region of interest using MATLAB's matrix indexing.

% Example: Cropping an image
cropped_img = img(50:250, 100:300, :);

Adjusting Brightness and Contrast

You can adjust the brightness and contrast of an image using the imadjust function.

% Example: Adjusting brightness and contrast
adjusted_img = imadjust(img, [0.2, 0.8], [0.1, 0.9]);

Saving the Edited Image

You can save the edited image using the imwrite function, specifying the file format.

% Example: Saving the edited image
imwrite(adjusted_img, 'edited_sample.jpg');


MATLAB's image processing capabilities allow you to perform basic image editing operations with ease. Whether it's resizing, cropping, or adjusting brightness, MATLAB provides the tools you need for simple image manipulations.

Enjoy using MATLAB for your basic image editing needs!