Getting Started with Image Processing

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
image processing is all about enhancing and extracting information from an image to analyze and understand our world better in this video we'll walk through a typical image processing workflow we'll use matlab and image processing toolbox to analyze deforestation in the amazon rainforest the amazon rainforest is the largest and most diverse rainforest in the world these are satellite images of the zhemangsum national forest in brazil which has one of the highest rates of deforestation in the amazon but there have been significant efforts in recent years to slow the deforestation let's analyze images taken every four years of the same region to see the impact of those conservation efforts first we'll have to identify the deforested regions in each image and then calculate their area in pixels we can then use this scale to convert the area from pixels to square kilometers let's head over to matlab to get started we have five images to work with representing various years let's import the one from 2000 when you bring the image into the workspace the name of the variable will match the name of the file by default we'll use a live script to document type and run our code to display an image in matlab you can use the function im show let's also add a simple title to our image this image has a height of 800 pixels and a width of 720 pixels in matlab this means we have an array with 800 rows and 720 columns color images are 3d arrays because we need to store the red green and blue values for each pixel these values are integers that range from 0 to 255. let's compare 2000 to 2016. you can use the function i am read to directly import an image into the workspace to display these images together use i am show pair with the montage option we can already see that the deforested area is larger in 2016 but to compare the two more accurately we'll need to isolate the deforested regions in image processing this is called segmentation the deforested regions appear to be brighter so we can use this brightness or intensity for segmentation it's easier to visualize intensities in a grayscale image you can use i am to gray to convert an image to grayscale grayscale images are 2d arrays because we only need one value the intensity for each pixel one way to examine these intensities is to create an intensity histogram the x-axis represents the intensity values and the y-axis is the pixel count most of the intensities are clustered here making it hard to isolate the bright deforested regions from the darker surrounding areas we'll want to adjust this histogram so we use more pixels that are darker and brighter which should increase the contrast of the image the function im adjust spreads the pixels out to match the intensity range better while still maintaining the original shape comparing the original and adjusted images the deforested regions are brighter and more prominent now we need to decide which pixels belong to the deforested areas one way is to threshold the intensity values if the intensity of the pixel is higher than the threshold then it's deforested if it's lower it's not picking a good threshold is tricky to find the right one you can use the image segmenter app you can find it in the apps tab in the image processing and computer vision section we'll start by loading our image we'll use the adjusted grayscale image from 2016. we already adjusted the contrast so we don't have to do it again let's start with a threshold tool the blue areas indicate what will be segmented based on your current threshold settings you can choose your method here the default tries to automatically pick an optimal threshold but you can also manually choose a threshold with this option a low threshold isolates the deforested areas well but also falsely segments some areas that aren't deforested a high threshold removes those false segmentations but then you lose some areas that are deforested it's all about balance in this case a threshold around 100 does a good job to view the result click show binary it looks pretty good but we can see a few small problems for example this squiggly line is not a deforested region but a river that shouldn't be segmented we can refine our segmentation using these options here let's try morphology which will allow us to modify the shape of the segmented areas choose the type of operation here since we want to remove the river let's try the open mask operation which removes areas smaller than a given shape for the shape choose one that resembles the areas you want to keep in our case the areas are square next set a size for the shape if it's too small then you might not remove the river but if it's too big you'll remove deforested areas in this case a length of three removes the river and leaves the rest mostly intact okay we've segmented one image so let's try another one how about 2004 we'll go back to our live script and import it convert it to grayscale and adjust the contrast then back in the app let's import the adjusted image looks like the same threshold also segments most of the deforested areas however this image contains some clouds from the atmosphere that block our view those clouds are falsely segmented due to being very bright also the text in the corners is being segmented this was the case in the 2016 image too it's not a big deal but it'd be nice if we could remove it so it looks like we're not going to be able to use intensity to segment this image how about color the deforested areas have a distinct brown color that's different from the white and dark green colors in the rest of the image we can segment based on color using the color thresholder app let's use the image from 2016 because it has more of that brown color that we're looking for next choose the color space to segment in different color spaces work better for different images so how do we choose well these point clouds can help they visualize the colors in a 3d space you'll want to pick the one that isolates the brown color the most these three are all equally good so let's just pick one and start how about hsv hue determines the color saturation sets the shade and value describes the brightness let's start with hue we can remove most of the green color with this alone as you move the slider the preview and point clouds update in real time this still leaves parts of the year text visible let's zoom in and get a closer look the remaining text is white which is hard to remove using hue instead we can use the fact that it's very bright and use the value slider so filter out the brightest pixels and it removes the remaining text okay let's go back and look at the binary image well that looks like a pretty good segmentation now we're ready to export the results you can export the image itself but since we're going to do this for multiple images let's generate a function instead the generated function takes in the rgb image as the input and it has two outputs the masked image which is the preview from the app and bw which is the binary image let's save our function so that we can use it in our script we'll save it as create mask in our current folder alright let's try it out on the image from 2004 last time the clouds got in our way this time it looks like our function was able to remove the clouds while preserving the deforested areas now that we have our segmentation it's time to calculate the area of the deforested regions the region props function calculates a lot of useful information about the segmented regions in an image we're only interested in the area of each region so let's use the area option then to get the total area we'll add them all up now this area is in pixels so we need to convert it to square kilometers remember that scale in the images we can use that to measure the scale we can use the image viewer app all right let's zoom in the app has a ruler tool that we can use to measure the length of this line it looks like 20 kilometers is about 51 pixels back in our script we can calculate the conversion factor then use that to find the total deforested area in square kilometers now we'll need to do this for all the images which we can do using the image batch processor app for this app you'll have to choose the folder that contains your images once they're loaded you'll see a preview of all the images to be processed next select the function to process each image if you click new the app generates a template to help you write your own function i've already written a processing function called calculate area let's take a look at it to work with the app the function must have an image as the input and any outputs formatted as a structure here we'll output both the binary image and the area in square kilometers back in the app we can browse for that function and process all the images the results appear over here for each image we can preview the segmentation and the area let's export to the workspace so we can analyze the results further we'll include everything in a table named all results we can see the deforested area increases over the years but not at a constant rate let's create a bar chart of the areas so we can see the trend there was a considerable jump between 2004 and 2008 after that there's a significant reduction in the deforestation rate showing the impact of conservation efforts we can see this in the segmented images too use the montage function to view a collection of images the segmented areas expand in 2008 then remain fairly constant in the next two images it's pretty cool to see how conservation efforts really can make a difference these files are available to download so you can try it out for yourself we've shown you some of the capabilities of image processing toolbox but there's so much more to explore our images focused on one small part of the amazon if you had more images of the surrounding regions you could use image registration to stitch the images together or if you had multi-spectral images you could process them to identify different types of vegetation the sky's the limit check out the image processing on-ramp or the image processing with matlab course to learn more welcome to image processing with matlab
Info
Channel: MATLAB
Views: 16,199
Rating: undefined out of 5
Keywords: MATLAB, Simulink, MathWorks
Id: nAVgUfk-ALE
Channel Id: undefined
Length: 13min 7sec (787 seconds)
Published: Fri Apr 30 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.