SlideShare a Scribd company logo
1 of 5
Download to read offline
could you draw uml diagram for this code
from PIL import Image, ImageTk # used Python Imaging Library (PIL) modules
import numpy as np # fundamental Python module for scientific computing
import os # os module is used for file and directory operations
# tkinter and its modules are used for creating a graphical user interface (gui)
import tkinter as tk
from tkinter import filedialog, messagebox
# Declaration and initialization of the global variables used in this program
# -------------------------------------------------------------------------------
# get the current directory where this program is placed
current_directory = os.path.dirname(os.path.realpath(__file__))
image_file_path = current_directory + '/thumbs_up.bmp' # default image
# Main function where this program starts execution
# -------------------------------------------------------------------------------
def start():
# create a window for the graphical user interface (gui)
gui = tk.Tk()
# set the title of the window
gui.title('Image Operations')
# set the background color of the window
gui['bg'] = 'SeaGreen1'
# create and place a frame on the window with some padding for all four sides
frame = tk.Frame(gui)
# using the grid method for layout management
frame.grid(row = 0, column = 0, padx = 15, pady = 15)
# set the background color of the frame
frame['bg'] = 'DodgerBlue4'
# read and display the default image which is a thumbs up emoji
gui_img = ImageTk.PhotoImage(file = image_file_path)
gui_img_panel = tk.Label(frame, image = gui_img)
# columnspan = 5 -> 5 columns as there are 5 buttons
gui_img_panel.grid(row = 0, column = 0, columnspan = 5, padx = 10, pady = 10)
# create and place five buttons below the image (button commands are expressed
# as lambda functions for enabling input arguments)
# ----------------------------------------------------------------------------
# the first button enables the user to open and view an image from a file
btn1 = tk.Button(frame, text = 'Open Image', width = 10)
btn1['command'] = lambda:open_image(gui_img_panel)
btn1.grid(row = 1, column = 0)
# create and place the second button that shows the image in grayscale
btn2 = tk.Button(frame, text = 'Grayscale', bg = 'gray', width = 10)
btn2.grid(row = 1, column = 1)
btn2['command'] = lambda:display_in_grayscale(gui_img_panel)
# create and place the third button that shows the red channel of the image
btn3 = tk.Button(frame, text = 'Red', bg = 'red', width = 10)
btn3.grid(row = 1, column = 2)
btn3['command'] = lambda:display_color_channel(gui_img_panel, 'red')
# create and place the third button that shows the green channel of the image
btn4 = tk.Button(frame, text = 'Green', bg = 'SpringGreen2', width = 10)
btn4.grid(row = 1, column = 3)
btn4['command'] = lambda:display_color_channel(gui_img_panel, 'green')
# create and place the third button that shows the blue channel of the image
btn5 = tk.Button(frame, text = 'Blue', bg = 'DodgerBlue2', width = 10)
btn5.grid(row = 1, column = 4)
btn5['command'] = lambda:display_color_channel(gui_img_panel, 'blue')
# wait for a gui event to occur and process each event that has occurred
gui.mainloop()
# Function for opening an image from a file
# -------------------------------------------------------------------------------
def open_image(image_panel):
global image_file_path # to modify the global variable image_file_path
# get the path of the image file selected by the user
file_path = filedialog.askopenfilename(initialdir = current_directory,
title = 'Select an image file',
filetypes = [('png files', '*.png'),
('bmp files', '*.bmp')])
# display an warning message when the user does not select an image file
if file_path == '':
messagebox.showinfo('Warning', 'No image file is selected/opened.')
# otherwise modify the global variable image_file_path and the displayed image
else:
image_file_path = file_path
img = ImageTk.PhotoImage(file = image_file_path)
image_panel.config(image = img)
image_panel.photo_ref = img
# Function for displaying the current image in grayscale
# -------------------------------------------------------------------------------
def display_in_grayscale(image_panel):
# open the current image as a PIL image
img_rgb = Image.open(image_file_path)
# convert the image to grayscale (img_grayscale has only one color channel
# whereas img_rgb has 3 color channels as red, green and blue)
img_grayscale = img_rgb.convert('L')
print('nFor the color image')
print('----------------------------------------------------------------------')
width, height = img_rgb.size
print('the width in pixels:', width, 'and the height in pixels:', height)
img_rgb_array = pil_to_np(img_rgb)
print('the dimensions of the image array:', img_rgb_array.shape)
print('nFor the grayscale image')
print('----------------------------------------------------------------------')
width, height = img_grayscale.size
print('the width in pixels:', width, 'and the height in pixels:', height)
img_grayscale_array = pil_to_np(img_grayscale)
print('the dimensions of the image array:', img_grayscale_array.shape)
# modify the displayed image
img = ImageTk.PhotoImage(image = img_grayscale)
image_panel.config(image = img)
image_panel.photo_ref = img
# Function for displaying a given color channel of the current image
# -------------------------------------------------------------------------------
def display_color_channel(image_panel, channel):
# red channel -> 0, green channel -> 1 and blue channel -> 2
if channel == 'red':
channel_index = 0
elif channel == 'green':
channel_index = 1
else:
channel_index = 2
# open the current image as a PIL image
img_rgb = Image.open(image_file_path)
# convert the current image to a numpy array
image_array = pil_to_np(img_rgb)
# traverse all the pixels in the image array
n_rows = image_array.shape[0]
n_cols = image_array.shape[1]
for row in range(n_rows):
for col in range(n_cols):
# make all the values 0 for the color channels except the given channel
for rgb in range(3):
if (rgb != channel_index):
image_array[row][col][rgb] = 0
# convert the modified image array (numpy) to a PIL image
pil_img = np_to_pil(image_array)
# modify the displayed image
img = ImageTk.PhotoImage(image = pil_img)
image_panel.config(image = img)
image_panel.photo_ref = img
# Function that converts a given PIL image to a numpy array and returns the array
# -------------------------------------------------------------------------------
def pil_to_np(img):
img_array = np.array(img)
return img_array
# Function that converts a given numpy array to a PIL image and returns the image
# -------------------------------------------------------------------------------
def np_to_pil(img_array):
img = Image.fromarray(np.uint8(img_array))
return img
# start() function is specified as the entry point (main function) where this
# program starts execution
if __name__== '__main__':
start()

More Related Content

Similar to could you draw uml diagram for this code from PIL import Image, Im.pdf

CE344L-200365-Lab7.pdf
CE344L-200365-Lab7.pdfCE344L-200365-Lab7.pdf
CE344L-200365-Lab7.pdfUmarMustafa13
 
Need helping adding to the code below to plot the images from the firs.pdf
Need helping adding to the code below to plot the images from the firs.pdfNeed helping adding to the code below to plot the images from the firs.pdf
Need helping adding to the code below to plot the images from the firs.pdfactexerode
 
Computer graphics
Computer graphics Computer graphics
Computer graphics shafiq sangi
 
Python 03-parameters-graphics.pptx
Python 03-parameters-graphics.pptxPython 03-parameters-graphics.pptx
Python 03-parameters-graphics.pptxTseChris
 
The Ring programming language version 1.9 book - Part 56 of 210
The Ring programming language version 1.9 book - Part 56 of 210The Ring programming language version 1.9 book - Part 56 of 210
The Ring programming language version 1.9 book - Part 56 of 210Mahmoud Samir Fayed
 
Pres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdfPres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdfRamziFeghali
 
The Ring programming language version 1.5.4 book - Part 47 of 185
The Ring programming language version 1.5.4 book - Part 47 of 185The Ring programming language version 1.5.4 book - Part 47 of 185
The Ring programming language version 1.5.4 book - Part 47 of 185Mahmoud Samir Fayed
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and ContainersRodolfo Carvalho
 
Image processing with matlab
Image processing with matlabImage processing with matlab
Image processing with matlabAman Gupta
 
The Ring programming language version 1.5.4 book - Part 48 of 185
The Ring programming language version 1.5.4 book - Part 48 of 185The Ring programming language version 1.5.4 book - Part 48 of 185
The Ring programming language version 1.5.4 book - Part 48 of 185Mahmoud Samir Fayed
 
Parallel Processing with IPython
Parallel Processing with IPythonParallel Processing with IPython
Parallel Processing with IPythonEnthought, Inc.
 
BKK16-211 Internet of Tiny Linux (io tl)- Status and Progress
BKK16-211 Internet of Tiny Linux (io tl)- Status and ProgressBKK16-211 Internet of Tiny Linux (io tl)- Status and Progress
BKK16-211 Internet of Tiny Linux (io tl)- Status and ProgressLinaro
 
Hybrid Intelligent Interface
Hybrid Intelligent InterfaceHybrid Intelligent Interface
Hybrid Intelligent InterfaceAlexey Egorov
 
Need an detailed analysis of what this code-model is doing- Thanks #St.pdf
Need an detailed analysis of what this code-model is doing- Thanks #St.pdfNeed an detailed analysis of what this code-model is doing- Thanks #St.pdf
Need an detailed analysis of what this code-model is doing- Thanks #St.pdfactexerode
 
Graphics & Animation with HTML5
Graphics & Animation with HTML5Graphics & Animation with HTML5
Graphics & Animation with HTML5Knoldus Inc.
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentNuvole
 

Similar to could you draw uml diagram for this code from PIL import Image, Im.pdf (20)

CE344L-200365-Lab7.pdf
CE344L-200365-Lab7.pdfCE344L-200365-Lab7.pdf
CE344L-200365-Lab7.pdf
 
Need helping adding to the code below to plot the images from the firs.pdf
Need helping adding to the code below to plot the images from the firs.pdfNeed helping adding to the code below to plot the images from the firs.pdf
Need helping adding to the code below to plot the images from the firs.pdf
 
Computer graphics
Computer graphics Computer graphics
Computer graphics
 
Python 03-parameters-graphics.pptx
Python 03-parameters-graphics.pptxPython 03-parameters-graphics.pptx
Python 03-parameters-graphics.pptx
 
The Ring programming language version 1.9 book - Part 56 of 210
The Ring programming language version 1.9 book - Part 56 of 210The Ring programming language version 1.9 book - Part 56 of 210
The Ring programming language version 1.9 book - Part 56 of 210
 
Pres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdfPres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdf
 
14709302.ppt
14709302.ppt14709302.ppt
14709302.ppt
 
The Ring programming language version 1.5.4 book - Part 47 of 185
The Ring programming language version 1.5.4 book - Part 47 of 185The Ring programming language version 1.5.4 book - Part 47 of 185
The Ring programming language version 1.5.4 book - Part 47 of 185
 
Built in function
Built in functionBuilt in function
Built in function
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and Containers
 
Image processing with matlab
Image processing with matlabImage processing with matlab
Image processing with matlab
 
The Ring programming language version 1.5.4 book - Part 48 of 185
The Ring programming language version 1.5.4 book - Part 48 of 185The Ring programming language version 1.5.4 book - Part 48 of 185
The Ring programming language version 1.5.4 book - Part 48 of 185
 
Parallel Processing with IPython
Parallel Processing with IPythonParallel Processing with IPython
Parallel Processing with IPython
 
BKK16-211 Internet of Tiny Linux (io tl)- Status and Progress
BKK16-211 Internet of Tiny Linux (io tl)- Status and ProgressBKK16-211 Internet of Tiny Linux (io tl)- Status and Progress
BKK16-211 Internet of Tiny Linux (io tl)- Status and Progress
 
Hybrid Intelligent Interface
Hybrid Intelligent InterfaceHybrid Intelligent Interface
Hybrid Intelligent Interface
 
Talk Code
Talk CodeTalk Code
Talk Code
 
Need an detailed analysis of what this code-model is doing- Thanks #St.pdf
Need an detailed analysis of what this code-model is doing- Thanks #St.pdfNeed an detailed analysis of what this code-model is doing- Thanks #St.pdf
Need an detailed analysis of what this code-model is doing- Thanks #St.pdf
 
Graphics & Animation with HTML5
Graphics & Animation with HTML5Graphics & Animation with HTML5
Graphics & Animation with HTML5
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven Development
 
Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
 

More from murtuzadahadwala3

Create an Executive Summary using the following report on investing .pdf
Create an Executive Summary using the following report on investing .pdfCreate an Executive Summary using the following report on investing .pdf
Create an Executive Summary using the following report on investing .pdfmurtuzadahadwala3
 
Create a ReportTopic Hudson Bay Mountain Estates (Smithers)The .pdf
Create a ReportTopic Hudson Bay Mountain Estates (Smithers)The .pdfCreate a ReportTopic Hudson Bay Mountain Estates (Smithers)The .pdf
Create a ReportTopic Hudson Bay Mountain Estates (Smithers)The .pdfmurtuzadahadwala3
 
Create an Executive Summary using the following information for the .pdf
Create an Executive Summary using the following information for the .pdfCreate an Executive Summary using the following information for the .pdf
Create an Executive Summary using the following information for the .pdfmurtuzadahadwala3
 
Create a python program that creates a database in MongoDB using API.pdf
Create a python program that creates a database in MongoDB using API.pdfCreate a python program that creates a database in MongoDB using API.pdf
Create a python program that creates a database in MongoDB using API.pdfmurtuzadahadwala3
 
Create a Java application that uses card layout with four cards with.pdf
Create a Java application that uses card layout with four cards with.pdfCreate a Java application that uses card layout with four cards with.pdf
Create a Java application that uses card layout with four cards with.pdfmurtuzadahadwala3
 
Create a Class Diagram for a Rectangle class that has one constructo.pdf
Create a Class Diagram for a Rectangle class that has one constructo.pdfCreate a Class Diagram for a Rectangle class that has one constructo.pdf
Create a Class Diagram for a Rectangle class that has one constructo.pdfmurtuzadahadwala3
 
Crane Company began the month of June with 1,630 units in beginning .pdf
Crane Company began the month of June with 1,630 units in beginning .pdfCrane Company began the month of June with 1,630 units in beginning .pdf
Crane Company began the month of June with 1,630 units in beginning .pdfmurtuzadahadwala3
 
Count the number of occurrences of an item in a matrix. Create a Pyt.pdf
Count the number of occurrences of an item in a matrix. Create a Pyt.pdfCount the number of occurrences of an item in a matrix. Create a Pyt.pdf
Count the number of occurrences of an item in a matrix. Create a Pyt.pdfmurtuzadahadwala3
 
COUNTRY IS INDIA1. Describe the legal environment of chosen countr.pdf
COUNTRY IS INDIA1. Describe the legal environment of chosen countr.pdfCOUNTRY IS INDIA1. Describe the legal environment of chosen countr.pdf
COUNTRY IS INDIA1. Describe the legal environment of chosen countr.pdfmurtuzadahadwala3
 
convert the following C code to Mips assembly with steps and comment.pdf
convert the following C code to Mips assembly with steps and comment.pdfconvert the following C code to Mips assembly with steps and comment.pdf
convert the following C code to Mips assembly with steps and comment.pdfmurtuzadahadwala3
 
copyReverse.c code please do not change anything in the code bes.pdf
copyReverse.c code please do not change anything in the code bes.pdfcopyReverse.c code please do not change anything in the code bes.pdf
copyReverse.c code please do not change anything in the code bes.pdfmurtuzadahadwala3
 
Contrast the location of a food distributor and a supermarket. (The .pdf
Contrast the location of a food distributor and a supermarket. (The .pdfContrast the location of a food distributor and a supermarket. (The .pdf
Contrast the location of a food distributor and a supermarket. (The .pdfmurtuzadahadwala3
 
Contabilidad del iPhone en Apple Inc. El 21 de octubre de 2008, Appl.pdf
Contabilidad del iPhone en Apple Inc. El 21 de octubre de 2008, Appl.pdfContabilidad del iPhone en Apple Inc. El 21 de octubre de 2008, Appl.pdf
Contabilidad del iPhone en Apple Inc. El 21 de octubre de 2008, Appl.pdfmurtuzadahadwala3
 
Contaminaci�n en la cadena log�stica de productos agr�colas a granel.pdf
Contaminaci�n en la cadena log�stica de productos agr�colas a granel.pdfContaminaci�n en la cadena log�stica de productos agr�colas a granel.pdf
Contaminaci�n en la cadena log�stica de productos agr�colas a granel.pdfmurtuzadahadwala3
 
Constructing Entity Relationship Diagram University workshop case st.pdf
Constructing Entity Relationship Diagram University workshop case st.pdfConstructing Entity Relationship Diagram University workshop case st.pdf
Constructing Entity Relationship Diagram University workshop case st.pdfmurtuzadahadwala3
 
Consider the international strategy of a current entrepreneurial ve.pdf
Consider the international strategy of a current  entrepreneurial ve.pdfConsider the international strategy of a current  entrepreneurial ve.pdf
Consider the international strategy of a current entrepreneurial ve.pdfmurtuzadahadwala3
 
Consider the network shown in the attached picture. Assume Distance .pdf
Consider the network shown in the attached picture. Assume Distance .pdfConsider the network shown in the attached picture. Assume Distance .pdf
Consider the network shown in the attached picture. Assume Distance .pdfmurtuzadahadwala3
 
Consider the DE PBC Article. Which of the following sources of capit.pdf
Consider the DE PBC Article. Which of the following sources of capit.pdfConsider the DE PBC Article. Which of the following sources of capit.pdf
Consider the DE PBC Article. Which of the following sources of capit.pdfmurtuzadahadwala3
 
Computer Programming Task- Assembly Language- STM32F3 DISCOVERY.pdf
Computer Programming Task- Assembly Language- STM32F3 DISCOVERY.pdfComputer Programming Task- Assembly Language- STM32F3 DISCOVERY.pdf
Computer Programming Task- Assembly Language- STM32F3 DISCOVERY.pdfmurtuzadahadwala3
 
Consider a population that grows according to the recursive rule Pn=.pdf
Consider a population that grows according to the recursive rule Pn=.pdfConsider a population that grows according to the recursive rule Pn=.pdf
Consider a population that grows according to the recursive rule Pn=.pdfmurtuzadahadwala3
 

More from murtuzadahadwala3 (20)

Create an Executive Summary using the following report on investing .pdf
Create an Executive Summary using the following report on investing .pdfCreate an Executive Summary using the following report on investing .pdf
Create an Executive Summary using the following report on investing .pdf
 
Create a ReportTopic Hudson Bay Mountain Estates (Smithers)The .pdf
Create a ReportTopic Hudson Bay Mountain Estates (Smithers)The .pdfCreate a ReportTopic Hudson Bay Mountain Estates (Smithers)The .pdf
Create a ReportTopic Hudson Bay Mountain Estates (Smithers)The .pdf
 
Create an Executive Summary using the following information for the .pdf
Create an Executive Summary using the following information for the .pdfCreate an Executive Summary using the following information for the .pdf
Create an Executive Summary using the following information for the .pdf
 
Create a python program that creates a database in MongoDB using API.pdf
Create a python program that creates a database in MongoDB using API.pdfCreate a python program that creates a database in MongoDB using API.pdf
Create a python program that creates a database in MongoDB using API.pdf
 
Create a Java application that uses card layout with four cards with.pdf
Create a Java application that uses card layout with four cards with.pdfCreate a Java application that uses card layout with four cards with.pdf
Create a Java application that uses card layout with four cards with.pdf
 
Create a Class Diagram for a Rectangle class that has one constructo.pdf
Create a Class Diagram for a Rectangle class that has one constructo.pdfCreate a Class Diagram for a Rectangle class that has one constructo.pdf
Create a Class Diagram for a Rectangle class that has one constructo.pdf
 
Crane Company began the month of June with 1,630 units in beginning .pdf
Crane Company began the month of June with 1,630 units in beginning .pdfCrane Company began the month of June with 1,630 units in beginning .pdf
Crane Company began the month of June with 1,630 units in beginning .pdf
 
Count the number of occurrences of an item in a matrix. Create a Pyt.pdf
Count the number of occurrences of an item in a matrix. Create a Pyt.pdfCount the number of occurrences of an item in a matrix. Create a Pyt.pdf
Count the number of occurrences of an item in a matrix. Create a Pyt.pdf
 
COUNTRY IS INDIA1. Describe the legal environment of chosen countr.pdf
COUNTRY IS INDIA1. Describe the legal environment of chosen countr.pdfCOUNTRY IS INDIA1. Describe the legal environment of chosen countr.pdf
COUNTRY IS INDIA1. Describe the legal environment of chosen countr.pdf
 
convert the following C code to Mips assembly with steps and comment.pdf
convert the following C code to Mips assembly with steps and comment.pdfconvert the following C code to Mips assembly with steps and comment.pdf
convert the following C code to Mips assembly with steps and comment.pdf
 
copyReverse.c code please do not change anything in the code bes.pdf
copyReverse.c code please do not change anything in the code bes.pdfcopyReverse.c code please do not change anything in the code bes.pdf
copyReverse.c code please do not change anything in the code bes.pdf
 
Contrast the location of a food distributor and a supermarket. (The .pdf
Contrast the location of a food distributor and a supermarket. (The .pdfContrast the location of a food distributor and a supermarket. (The .pdf
Contrast the location of a food distributor and a supermarket. (The .pdf
 
Contabilidad del iPhone en Apple Inc. El 21 de octubre de 2008, Appl.pdf
Contabilidad del iPhone en Apple Inc. El 21 de octubre de 2008, Appl.pdfContabilidad del iPhone en Apple Inc. El 21 de octubre de 2008, Appl.pdf
Contabilidad del iPhone en Apple Inc. El 21 de octubre de 2008, Appl.pdf
 
Contaminaci�n en la cadena log�stica de productos agr�colas a granel.pdf
Contaminaci�n en la cadena log�stica de productos agr�colas a granel.pdfContaminaci�n en la cadena log�stica de productos agr�colas a granel.pdf
Contaminaci�n en la cadena log�stica de productos agr�colas a granel.pdf
 
Constructing Entity Relationship Diagram University workshop case st.pdf
Constructing Entity Relationship Diagram University workshop case st.pdfConstructing Entity Relationship Diagram University workshop case st.pdf
Constructing Entity Relationship Diagram University workshop case st.pdf
 
Consider the international strategy of a current entrepreneurial ve.pdf
Consider the international strategy of a current  entrepreneurial ve.pdfConsider the international strategy of a current  entrepreneurial ve.pdf
Consider the international strategy of a current entrepreneurial ve.pdf
 
Consider the network shown in the attached picture. Assume Distance .pdf
Consider the network shown in the attached picture. Assume Distance .pdfConsider the network shown in the attached picture. Assume Distance .pdf
Consider the network shown in the attached picture. Assume Distance .pdf
 
Consider the DE PBC Article. Which of the following sources of capit.pdf
Consider the DE PBC Article. Which of the following sources of capit.pdfConsider the DE PBC Article. Which of the following sources of capit.pdf
Consider the DE PBC Article. Which of the following sources of capit.pdf
 
Computer Programming Task- Assembly Language- STM32F3 DISCOVERY.pdf
Computer Programming Task- Assembly Language- STM32F3 DISCOVERY.pdfComputer Programming Task- Assembly Language- STM32F3 DISCOVERY.pdf
Computer Programming Task- Assembly Language- STM32F3 DISCOVERY.pdf
 
Consider a population that grows according to the recursive rule Pn=.pdf
Consider a population that grows according to the recursive rule Pn=.pdfConsider a population that grows according to the recursive rule Pn=.pdf
Consider a population that grows according to the recursive rule Pn=.pdf
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfNirmal Dwivedi
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesSHIVANANDaRV
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111GangaMaiya1
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17Celine George
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxCeline George
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 

Recently uploaded (20)

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 

could you draw uml diagram for this code from PIL import Image, Im.pdf

  • 1. could you draw uml diagram for this code from PIL import Image, ImageTk # used Python Imaging Library (PIL) modules import numpy as np # fundamental Python module for scientific computing import os # os module is used for file and directory operations # tkinter and its modules are used for creating a graphical user interface (gui) import tkinter as tk from tkinter import filedialog, messagebox # Declaration and initialization of the global variables used in this program # ------------------------------------------------------------------------------- # get the current directory where this program is placed current_directory = os.path.dirname(os.path.realpath(__file__)) image_file_path = current_directory + '/thumbs_up.bmp' # default image # Main function where this program starts execution # ------------------------------------------------------------------------------- def start(): # create a window for the graphical user interface (gui) gui = tk.Tk() # set the title of the window gui.title('Image Operations') # set the background color of the window gui['bg'] = 'SeaGreen1' # create and place a frame on the window with some padding for all four sides frame = tk.Frame(gui) # using the grid method for layout management frame.grid(row = 0, column = 0, padx = 15, pady = 15) # set the background color of the frame frame['bg'] = 'DodgerBlue4' # read and display the default image which is a thumbs up emoji gui_img = ImageTk.PhotoImage(file = image_file_path) gui_img_panel = tk.Label(frame, image = gui_img) # columnspan = 5 -> 5 columns as there are 5 buttons gui_img_panel.grid(row = 0, column = 0, columnspan = 5, padx = 10, pady = 10) # create and place five buttons below the image (button commands are expressed
  • 2. # as lambda functions for enabling input arguments) # ---------------------------------------------------------------------------- # the first button enables the user to open and view an image from a file btn1 = tk.Button(frame, text = 'Open Image', width = 10) btn1['command'] = lambda:open_image(gui_img_panel) btn1.grid(row = 1, column = 0) # create and place the second button that shows the image in grayscale btn2 = tk.Button(frame, text = 'Grayscale', bg = 'gray', width = 10) btn2.grid(row = 1, column = 1) btn2['command'] = lambda:display_in_grayscale(gui_img_panel) # create and place the third button that shows the red channel of the image btn3 = tk.Button(frame, text = 'Red', bg = 'red', width = 10) btn3.grid(row = 1, column = 2) btn3['command'] = lambda:display_color_channel(gui_img_panel, 'red') # create and place the third button that shows the green channel of the image btn4 = tk.Button(frame, text = 'Green', bg = 'SpringGreen2', width = 10) btn4.grid(row = 1, column = 3) btn4['command'] = lambda:display_color_channel(gui_img_panel, 'green') # create and place the third button that shows the blue channel of the image btn5 = tk.Button(frame, text = 'Blue', bg = 'DodgerBlue2', width = 10) btn5.grid(row = 1, column = 4) btn5['command'] = lambda:display_color_channel(gui_img_panel, 'blue') # wait for a gui event to occur and process each event that has occurred gui.mainloop() # Function for opening an image from a file # ------------------------------------------------------------------------------- def open_image(image_panel): global image_file_path # to modify the global variable image_file_path # get the path of the image file selected by the user file_path = filedialog.askopenfilename(initialdir = current_directory, title = 'Select an image file', filetypes = [('png files', '*.png'), ('bmp files', '*.bmp')]) # display an warning message when the user does not select an image file if file_path == '':
  • 3. messagebox.showinfo('Warning', 'No image file is selected/opened.') # otherwise modify the global variable image_file_path and the displayed image else: image_file_path = file_path img = ImageTk.PhotoImage(file = image_file_path) image_panel.config(image = img) image_panel.photo_ref = img # Function for displaying the current image in grayscale # ------------------------------------------------------------------------------- def display_in_grayscale(image_panel): # open the current image as a PIL image img_rgb = Image.open(image_file_path) # convert the image to grayscale (img_grayscale has only one color channel # whereas img_rgb has 3 color channels as red, green and blue) img_grayscale = img_rgb.convert('L') print('nFor the color image') print('----------------------------------------------------------------------') width, height = img_rgb.size print('the width in pixels:', width, 'and the height in pixels:', height) img_rgb_array = pil_to_np(img_rgb) print('the dimensions of the image array:', img_rgb_array.shape) print('nFor the grayscale image') print('----------------------------------------------------------------------') width, height = img_grayscale.size print('the width in pixels:', width, 'and the height in pixels:', height) img_grayscale_array = pil_to_np(img_grayscale) print('the dimensions of the image array:', img_grayscale_array.shape) # modify the displayed image img = ImageTk.PhotoImage(image = img_grayscale) image_panel.config(image = img) image_panel.photo_ref = img # Function for displaying a given color channel of the current image # ------------------------------------------------------------------------------- def display_color_channel(image_panel, channel):
  • 4. # red channel -> 0, green channel -> 1 and blue channel -> 2 if channel == 'red': channel_index = 0 elif channel == 'green': channel_index = 1 else: channel_index = 2 # open the current image as a PIL image img_rgb = Image.open(image_file_path) # convert the current image to a numpy array image_array = pil_to_np(img_rgb) # traverse all the pixels in the image array n_rows = image_array.shape[0] n_cols = image_array.shape[1] for row in range(n_rows): for col in range(n_cols): # make all the values 0 for the color channels except the given channel for rgb in range(3): if (rgb != channel_index): image_array[row][col][rgb] = 0 # convert the modified image array (numpy) to a PIL image pil_img = np_to_pil(image_array) # modify the displayed image img = ImageTk.PhotoImage(image = pil_img) image_panel.config(image = img) image_panel.photo_ref = img # Function that converts a given PIL image to a numpy array and returns the array # ------------------------------------------------------------------------------- def pil_to_np(img): img_array = np.array(img) return img_array # Function that converts a given numpy array to a PIL image and returns the image # ------------------------------------------------------------------------------- def np_to_pil(img_array):
  • 5. img = Image.fromarray(np.uint8(img_array)) return img # start() function is specified as the entry point (main function) where this # program starts execution if __name__== '__main__': start()