35-Displaying Images in Matlab
Sections
- Effect of sigma on Gaussian Noise
- Displaying images in Matlab
- Displaying images in Python
To Do LIST
- 1- Copy code in Colab file
- 2- add more python method to display imageĀ
Section 1- Effect of sigma on Gaussian Noise
I didn't say in the previous image what the range of our pictures would tend to be, okay? Remember I told you an image might go from, you know, 0 to 1. And that would be from the darkest black to the brightest white. Well, if I did that and I had a sigma of two. You would get black and white all over the place. And yet, when I go back here, sigma of two is just a small variation.

Whereas sigma of 64 was a big variation. Why? In this image, we have this notion of maybe minus 127 was black and plus 128 was white. When we talk about the amount of noise in an image in terms of the intensity. It has to be with respect to sort of what's the overall range. So another reason to use doubles in your images. And to think of them as going from 0 to 1, then we can talk about a sigma of, you know, 0.1. Well, that's a tenth of sort of going from black to white. If you want to use something arbitrary like 0 to 255. You can do that. First of all, use 0.0 to 255.0, so use a floating-point number. And then you're going to have to say, okay, I guess a sigma of 0.1 in one case would be a sigma of, like, 25 in another case. Right, because I've stretched the whole thing out. So you have to worry about the magnitude of sigma with respect to the overall range of your image.
Section 2- Displaying images in Matlab
This will c, catch you number, numerous times when you go to display an image. All right, because now you have to tell the machine, okay I've got this image. How do you want it displayed? Matlab has a large number of ways of displaying images. If you have the imshow function which I think actually comes from the Image Processing Toolbox. You can show it this way where you'd tell it low and high. And it will display, anything with the value low or lower as black, anything higher than high as white, okay? You can also do imshow and just give it this empty array. And it will scale the image for you automatically. That is, it'll find the minimum value in the image and say, okay, that's going to be black. It'll find the maximum. It'll say, that'll be white, and it'll scale you. There's another function called imagesc, for image scale. It's a much older function. It's not in Image Processing Toolbox, which will also display it. Don't get caught between this question of how I display an image versus how I use an image. Just I just finished teaching part of this course here at Georgia Tech. I had some people doing, computing some gradients. They computed some gradients, which involves substructions and derivatives and all that stuff. And then one guy, he normalized his picture to go from 0 to 255, before he computed with it. You would only normalize it in order to display it, not in order to compute with it.Ā
Section 3- Displaying Images in python
In Python, you can use various libraries to display images. One of the commonly used libraries for image processing is Pillow (PIL), and for displaying images, you can use the Image module from Pillow. Here's a simple example:
from PIL import Image
from IPython.display import display # Only required if you are using a Jupyter notebook
# Open an image file
image_path = 'path/to/your/image.jpg'
img = Image.open(image_path)
# Display the image
img.show() # This will open the default image viewer
# If you are using a Jupyter notebook, you can use the display function to show the image directly in the notebook
# display(img)
If you're working in a Jupyter notebook, using IPython.display is a convenient way to display images directly in the notebook. If you're working in a script or another environment, the img.show() method will open the default image viewer associated with your system.