Task 1: Converting from RGB to Gray Scale Image

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

python

In [2]:
I image.shape
Out[2]: (300, 451, 3)
Task 1: Converting from RGB to Gray Scale Image
Create the gray scale image, represented by the 2D Numpy array image_gray from the RGB image tensor image above.
To do this, for each pixel (i,j), you can use the formula
Yij = 0.2125 x R;j + 0.7154 × G¡j + 0.0721 × Bij,
where Y;; denotes the intensity of that pixel in gray scale image image_gray , and R;j, Gij, Bij denotes the intensity of that pixel in the RGB image
respectively.
Of course in your code you're encouraged to use array implementations/functions instead of looping through every pixel.
In [3]:
I # write your code to generate the array image_gray here
please rerun your code before submission
# you can then use the following code to show the gray scale image
plt.imshow(image_gray,plt.get_cmap('gray'))
Out[3]: <matplotlib.image. AxesImage at Øx7f9706e43610>
50
100
150
Transcribed Image Text:In [2]: I image.shape Out[2]: (300, 451, 3) Task 1: Converting from RGB to Gray Scale Image Create the gray scale image, represented by the 2D Numpy array image_gray from the RGB image tensor image above. To do this, for each pixel (i,j), you can use the formula Yij = 0.2125 x R;j + 0.7154 × G¡j + 0.0721 × Bij, where Y;; denotes the intensity of that pixel in gray scale image image_gray , and R;j, Gij, Bij denotes the intensity of that pixel in the RGB image respectively. Of course in your code you're encouraged to use array implementations/functions instead of looping through every pixel. In [3]: I # write your code to generate the array image_gray here please rerun your code before submission # you can then use the following code to show the gray scale image plt.imshow(image_gray,plt.get_cmap('gray')) Out[3]: <matplotlib.image. AxesImage at Øx7f9706e43610> 50 100 150
Cjupyter homework_4 (autosaved)
Logout
File
Edit
View
Insert
Cell
Kernel
Widgets
Help
|Python 3 O
Not Trusted
Run I C »
Code
For this homework, you should write your code with basic Python or Numpy, and are not allowed to use any other packages/functions for image
processing or scientific computing.
Load the image
You can use the following codes to load the image. You're required to use this image throughout this homework.
In [1]:
I import numpy as np
import matplotlib.pyplot as plt
from skimage import data
image = data.chelsea()
plt.imshow (image)
Out[1]: <matplotlib.image. AxesImage at Ox1f87c4e87c0>
50
100
150
200
250
100
200
300
400
image is a 3-d Numpy array, where the axis 0 and 1 correspdonds to 2D pixels, and axis 2 corresponds to RGB channels.
In [2]:
I image.shape
Transcribed Image Text:Cjupyter homework_4 (autosaved) Logout File Edit View Insert Cell Kernel Widgets Help |Python 3 O Not Trusted Run I C » Code For this homework, you should write your code with basic Python or Numpy, and are not allowed to use any other packages/functions for image processing or scientific computing. Load the image You can use the following codes to load the image. You're required to use this image throughout this homework. In [1]: I import numpy as np import matplotlib.pyplot as plt from skimage import data image = data.chelsea() plt.imshow (image) Out[1]: <matplotlib.image. AxesImage at Ox1f87c4e87c0> 50 100 150 200 250 100 200 300 400 image is a 3-d Numpy array, where the axis 0 and 1 correspdonds to 2D pixels, and axis 2 corresponds to RGB channels. In [2]: I image.shape
Expert Solution
Step 1

form PIL import Image, ImageOps
im1 = Image.open(r"C:\Users\System-Pc\Desktop\a.JPG")
im2 = ImageOps.grayscale(im1)
im2.show()

 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Introduction to computer system
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education