官术网_书友最值得收藏!

Time for action – importing and displaying an image

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:

  1. Ensure that your current folder (its contents are shown in the Current Folder window) contains the image. If not, either copy it there or select the folder that contains it.
  2. Click in the Command Window area to be able to write something in the command line. Once you see a blinking cursor in the command line, you are ready to type.
  3. Type the following commands in the command line:
    >> img = imread('my_image.bmp');
    >> imshow(img)
  4. A window displaying the selected image must now be open. You can maximize, minimize, or adjust its size according to your liking.

What just happened?

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:\images\my_image.bmp');

Either way, imread stores the image in the variable img which is a matrix of size equal to that of the image.

Note

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/.

Importing and displaying an image using imtool

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:

  • Navigate the image using a smaller, overview window Importing and displaying an image using imtool
  • Inspect pixel values in a neighborhood of your choice Importing and displaying an image using imtool
  • Display image information Importing and displaying an image using imtool
  • Adjust image contrast Importing and displaying an image using imtool
  • Get Help.Importing and displaying an image using imtool
  • Crop the image Importing and displaying an image using imtool
  • Measure distances Importing and displaying an image using imtool
  • Zoom in/out Importing and displaying an image using imtool
  • Drag image to pan Importing and displaying an image using imtool
  • Adjust contrast/brightness via mouse motion Importing and displaying an image using imtool
  • Change the scale of the displayed image Importing and displaying an image using imtool
主站蜘蛛池模板: 兴国县| 黎川县| 上犹县| 宜宾市| 宣威市| 专栏| 十堰市| 邓州市| 蓝山县| 和硕县| 隆化县| 隆尧县| 赤壁市| 禄丰县| 龙山县| 诸城市| 崇仁县| 舒兰市| 沙坪坝区| 惠安县| 湘西| 视频| 鹤岗市| 瑞安市| 得荣县| 新源县| 铜陵市| 石阡县| 施甸县| 民乐县| 科尔| 淮北市| 香格里拉县| 宝坻区| 六盘水市| 社旗县| 安溪县| 南漳县| 长丰县| 许昌市| 兰溪市|