Last active
November 14, 2023 17:50
-
-
Save aishwarya-singh25/57637da528de738e7adb4da824843863 to your computer and use it in GitHub Desktop.
Preprocessing Techniques
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage import exposure | |
#adjusting brightness | |
image = imread('images.jpeg') | |
image_bright = exposure.adjust_gamma(image, gamma=0.5,gain=1) | |
image_dark = exposure.adjust_gamma(image, gamma=1.5,gain=1) | |
# plotting images | |
plt.subplot(131), imshow(image) | |
plt.title('Original Image') | |
plt.subplot(132),imshow(image_bright) | |
plt.title('Bright Image') | |
plt.subplot(133),imshow(image_dark) | |
plt.title('Dark Image') | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image = imread('warriors.jpg') | |
# selecting part of the image only | |
cropped = image[100:(img.shape[0]-100),100:(img.shape[1]-100)] | |
plt.subplot(121), imshow(image) | |
plt.title('Original Image') | |
plt.subplot(122),imshow(cropped) | |
plt.title('Cropped Image') | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from numpy import fliplr, flipud | |
dog = imread('Puppy.jpg') | |
cat = imread('whiskers.jpg') | |
dog_flip = fliplr(dog) | |
cat_flip = fliplr(cat) | |
plt.subplot(141), imshow(dog) | |
plt.subplot(142), imshow(dog_flip) | |
plt.subplot(143), imshow(cat) | |
plt.subplot(144), imshow(cat_flip) | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage.io import imread, imshow | |
from skimage import data | |
image = data.astronaut() | |
imshow(image) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage.filters import median | |
image = imread('images.jpeg', as_gray=True) | |
image_median = median(image) | |
# plotting images | |
plt.subplot(121), imshow(image) | |
plt.title('Original Image') | |
plt.subplot(122),imshow(image_median) | |
plt.title('Smooth Image') | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image_gray = imread('images.jpeg', as_gray=True) | |
print(image_gray.shape) | |
print(image_gray) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage.io import imread, imshow | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
image_color = imread('images.jpeg', as_gray=False) | |
print(image_color.shape) | |
imshow(image_color) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage.io import imread, imshow | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
image_gray = imread('images.jpeg', as_gray=True) | |
imshow(image_gray) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
red_channel = image_color*[1,0,0] | |
imshow(red_channel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage.transform import rescale | |
img = imread('images.jpeg') | |
img_rescaled = rescale(img, scale=(0.5, 0.5)) | |
plt.subplot(121), imshow(img) | |
plt.title('Original Image') | |
plt.subplot(122), imshow(img_rescaled) | |
plt.title('Rescaled Image') | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage.transform import resize | |
img = imread('images.jpeg') | |
#resize image | |
img_resized = resize(img, (300, 300)) | |
#plot images | |
plt.subplot(121), imshow(img) | |
plt.title('Original Image') | |
plt.subplot(122), imshow(img_resized) | |
plt.title('Resized Image') | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage.color import rgb2gray | |
img = imread('images.jpeg') | |
img_new = rgb2gray(img) | |
plt.subplot(121), imshow(img) | |
plt.title('RGB Format') | |
plt.subplot(122), imshow(img_new) | |
plt.title('Grayscale Format') | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage.color import rgb2hsv | |
img = imread('images.jpeg') | |
img_new = rgb2hsv(img) | |
plt.subplot(121), imshow(img) | |
plt.title('RGB Format') | |
plt.subplot(122), imshow(img_new) | |
plt.title('HSV Format') | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage.transform import rotate | |
image = imread('tilt_image.png') | |
image_rotated = rotate(image, angle=45) | |
imshow(image_rotated) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage.transform import rotate | |
image = imread('tilt_image.png') | |
image_rotated = rotate(image, angle=45, resize=True) | |
imshow(image_rotated) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage.filters import sobel_h | |
image = imread('images.jpeg', as_gray=True) | |
image_sobelh = sobel_h(image) | |
# plotting images | |
plt.subplot(121), imshow(image) | |
plt.title('Original Image') | |
plt.subplot(122),imshow(image_sobelh, cmap = True) | |
plt.title('Horizontal Edge') | |
plt.show() |
'rescale_image.py' is very problematic (at least for me (Python 3.7, scikit-image 0.18.3)):
img_rescaled = rescale(img, scale=(0.5, 0.5))
produces "ValueError: Supply a single scale, or one value per spatial axis" !!
If I change it toimg_rescaled = rescale(img, 0.5)
, it worksplt.subplot(122), imshow(img_rescaled)
produces "TypeError: Invalid shape (140, 114, 2) for image data" !!
Come on, this is too much guys!
Where are the images used in the code stored ??????????????
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks