Let's assume that you have an image called my_image.bmp
, which you want to import and then display in MATLAB. The steps you should follow are these:
>> img = imread('my_image.bmp'), >> imshow(img)
The steps you followed in the previous section used two predefined MATLAB functions, one for opening an image (imread
) and one for displaying it (imshow
). Step 1 is a prerequisite for imread
to find the file. An alternative to navigating to the folder containing the image would be to include the full path to the filename given as input. If, for example, the folder containing the image was C:images
,then the first command would be:
>> img = imread('C:imagesmy_image.bmp'),
Either way, imread
stores the image in the variable img
which is a matrix of size equal to that of the image.
The image used in the previous example, as well as all images and videos used throughout this book, can be found at the author's website. Its URL is http://www.cvrlab.com/gsiogkas/.
Using the command line is not the only way to open and display images. MATLAB also provides a basic image processing tool, called imtool
. This tool can be invoked by typing its name in the command line, or by clicking on its icon on the ribbon in the APPS tab. If you select to invoke imtool
, a new window which includes basic image manipulation choices, opens. To open an image in imtool
, we must click on File and then Open… to browse through the folders and load the image of our choice. Let's work with the same image as before, namely, my_image.bmp
. Once the image is open in imtool
, we can see and access most available functionalities of the tool on its toolbar. Starting from left to right, the icons appearing in the toolbar can be used to: