How to Turn Photos into Pencil Sketches Using Python
In this tutorial, we will learn how to create a desktop application using Python and the Tkinter library to convert images into pencil sketches. We will use libraries like OpenCV and Pillow for image manipulation.
This Python Project Will Make Your Photos Look Hand Drawn!
# Colors
co0 = "#f0f3f5" # Black
co1 = "#feffff" # White
co2 = "#4fa882" # Green
co3 = "#38576b" # Value
co4 = "#403d3d" # Letter
co5 = "#e06636" # Profit
co6 = "#038cfc" # Blue
๐ Donate and help us create more amazing content!
๐ Every contribution makes a difference!
โ Buy me a coffee: https://buymeacoffee.com/usandopython
๐Support this channel
https://www.youtube.com/channel/UCpL2Gru508Z39oPqu1FIg4Q/join
Show More Show Less View Video Transcript
0:00
hello guys welcome back to the channel here so today we are going to create a very good project okay for those who are
0:07
learning Python and want to practics so this project is called pencil sketch
0:12
converter okay so basically in this project okay we create we'll convert any image into something like which was
0:20
drawn by using paint something like that okay so let me show what I mean so the project works like this see first I need
0:26
to choose one image so I'm going to choose this image of Neymar okay I'm just going to click on it so this is
0:34
Neymar okay so I can convert this image into pencil sketch so for that I just need to make some change here so for
0:40
example I can change something like this so I just need to adjust here because for something like this now see this
0:47
image is looking like it was drawing by using pencil okay so I can make it more bold something like that okay more
0:54
contrast so this is what we are going to build okay in this project so this Pro
1:00
is very cool okay it's really good okay uh especially for those work with image
1:05
okay so you want to convert your image into pencil sketch so you can make use of this project so after that okay I
1:12
just I can click here on Save okay if I click on Save and I just need to choose where I want to save it for example I'm
1:18
going to save it here in my documents and I can just click on Save I need to give us a name okay I'm going to call it
1:25
Neymar Neymar and by default you will save it on P G and click just on Save
1:32
and boom now just let me go to that folder so I need to come here this is the fold so this is the image that we
1:38
just converted if I open it this is the image that we just convert into sketch
1:43
okay so this is the project that we are going to create so if you're not subscribed to this Channel please subscribe to the channel give a like to
1:49
the video and let's start building our project see in order to create this project first we need to create this
1:57
image okay uh the main window so for us to create a main windows we are going to do something like this okay so let me
2:04
first minimize this thing and let's start building our main windows so first we need to import tier okay I'm just
2:10
going to do some this from tiin sorry uh from
2:15
tier import okay let's import everything from T iner then after that let's do
2:22
something like this also okay so let's do something like this also from T
2:27
import TK ttk and file dialog so we we will need this in future okay
2:35
and the the next thing that we will do here we we will use the pillow uh
2:41
Library okay so pillow library is a library that help us to work with uh image in Python but for that you need to
2:49
install first pill if you don't have pill install on your machine so in order to start pillow you need to do something
2:55
like this so you need to go into your terminal and enter the following commands the command that you need to
3:02
enter to install pillow is this one you just enter something like this P oh sorry not pillow pip
3:09
install pillow okay so you need to install pillow so that you can you'll be able to work with this Library I have
3:16
installed so I'm not going to install it so you just enter this command and then hit enter it will install it by itself
3:22
so apart of that you need to install uh open CV so in order to open CV in order
3:28
to install open CV you need to install you need to enter this command then hit enter okay so don't need to work I'm
3:34
going to keep all this command inside in the description of this video so that you can go there and grab the code and
3:39
install them perfect so so after that okay as I said you will need to import
3:46
pill and open C on your script so it will be something like this see you need to do something like this okay from pill
3:52
import image TK comma image comma image perfect then you'll need to import
3:58
also open CV you just do something like this okay import
4:04
CV2 so after that now let's start building our main window so in order to
4:09
build our main window so there are some colors that we are going to use in this tutorial so these colors I'm going to keep them in the description of the
4:15
video but for me I'm just going to grab them and paste here so those are the colors that we are going to use in this
4:21
project so I'm going to keep them in the description of the video so after that we need to create the a main window so
4:27
for that we are going to do something like this window so window will be equal TK open and
4:33
close and do T is a capital K is a small okay then after that let's define the
4:39
title of our window window. title will be uh open and close so let's do
4:45
something like this pencil pencil sketch
4:51
converter converter then after that let's define also the geometry of our window the
4:58
dimension of the window let's windows. geometry windows. geometry will be open
5:04
and close so I'm going to do something like this and uh the size will be
5:10
450 x 550 and then let's do some uh
5:16
window let's define also the background color of our windows so for that I'm going to do window. configure configure
5:22
window do configure open and close so I'm going to configure the background back this way back ground will be equal
5:32
core one okay don't forget those colors we Define here them after that I'm going to see if you check my window okay I'm
5:39
not able to change the dimension of this window so I'm going in order to enable this so I need to do something like this
5:46
window window do resizable res resizable
5:52
resizable this way open and close oh sorry open and close then just do something like this width width will be
5:59
equal fails okay will be equal fails comma height okay I'm going to Define
6:07
also the height so this way I'm going to block so that the height and the width cannot be changed so I'm going to use
6:12
also fails save so in order to see this thing uh running I'm going to do this
6:19
okay I need to call the main window so that it the loop can be running so I'm going to do something like this window
6:25
do main Loop okay main Loop this way open and close perfect now I'm going to
6:32
run this to see the result and boom as you can see now we have the main window of how up so apart of that I'm going to
6:40
Define some kind of style here in inside of this window so for that I'm just I'm to come here and I will do something
6:46
like this style the style will be equal ttk do
6:54
style what's we what I'm going to St I'm going to St the window okay the window that I want to style so this one is a
7:01
mistake is supposed to be small t Okay this way then let's make use of this style okay so I'm going in order to make
7:07
use of this sty I need to do something like this style I need to call the Style again dot team this way teamore U so
7:15
this way I'm going to use this team okay so like not I'm going to use this I'm going to choose a team that I'm going to
7:21
use inside of this window so for that I'm going to do team do style. team use
7:26
uncore so there are a lot of style that you can use you can apply instead of the app so I'm going to use this one clam
7:35
save and if I run this uh there be nothing actually it will be something
7:40
just like that very well perfect so down the next step that we need to do something like this if we see our app
7:46
okay so this app is kind of there are uh I will say like three um three is
7:52
divided into three parts okay so the first part is this one which we have where do we have the title of the the
7:58
app then we have this uh this area where the it shows the image and we have this
8:04
area so where it show the configurations where like those boms and this those those things also those scales okay so
8:10
in order to do this division I'm going to create three frames so that I can separate the window so for that I'm
8:15
going to do this okay I'll come here and below this style I'll do something like this okay first I'm going to create one
8:23
frame so the first frame that I'm going to create will be the frame that will be having the title of the app so it could
8:29
be something like this Frame undor top open and close will be something like
8:34
frame open window okay so I'm going to create this from inside of window then
8:39
I'm going to give the width for width will be 450 comma height also height will be 50
8:47
for this one andj so now we need to show this Frame inside of our wind okay for
8:53
that I'm going to use something like this again I'm going to call the frame top again frame top. grid I will use
8:59
grid because grid is very good to separate okay when you're going to divide the main window grid is the best
9:04
option I'll say that grid them I'm going to use row so row zero comma will be in
9:11
the column okay column column will be zero also comma
9:17
pad X will be equal 10 comma and Pad y will be equal five perfect I'm going
9:26
to save this okay so now if I run this guy okay V and it's there okay so I'm I'm
9:32
going to change the color so that we can see if it is there or not okay let me use code to save and run perfect as you
9:39
can see now this is the one we are going to use for to show the title of the app so now let's get another one that will
9:45
show us the image okay so for that I'm just going to copy this one copy paste
9:50
and paste I'm going to change the name it will be frame preview preview so that
9:56
it will show okay preview so that it will we we are going to use this one to show the image frame preview so this
10:04
everything will be good but only here we are going to change to to to20 okay
10:09
220 and this guy will go to row one okay
10:16
and everything will keep the way it is perfect so now this guy is called to
10:21
okay I'm just going to change color so that we can see if it is there or save and run boom as you can see this is the
10:27
frame for preview so now we we need to create another frame for the bottoms okay so I'm going to copy this again
10:34
come down and paste okay so this Frame we are we are going to call it as a
10:40
controls because there will be a lot of bottons a lot of defin definition so that let's use controls so this controls
10:48
okay everything will be the way that it is but this guy let's change to
10:53
260 okay perfect good and it's going to it will go down okay to row two save and
11:00
run perfect everything is there okay so now let's put back those colors into
11:06
white so for that let's change one one and one
11:11
save so now HOH mistake so now the next thing that we need to do is uh is to
11:19
create the title of the app okay so this title like pencil sketch converters so for that we need to create a label okay
11:26
so I'm going to come here I'm going to comment here so logo okay logo and title
11:33
logo and we know that there is not logo but let's just go like this I'm going to call some this logo will be equal oh
11:40
sorry will be equal what equal what I'm going to use a label not frame a lab I'm
11:46
going to get a label oh mistake a label so this label will be inside of
11:52
the frame top comma so the test will be equal and we call it P pencil sketch
12:00
converter okay this will be the title of this one pencil oh pencil see
12:09
pencil sketch pencil sketch converter
12:15
converter penil sketch converter okay font uh the font will be equal open and
12:23
close so we are going to use Arial which is a very good font comma and 16 for the
12:30
size and let's use Bal okay Bal so that it can be very good looking and from
12:38
here okay let's use comma let's use Co one okay and Co one for b bj okay BJ
12:47
will be equal co1 comma and FG the color
12:53
of the test will be core 4 okay will be white color perfect so now uh after this
13:01
now let's pack this one okay let's use logo dot let's use pack since it will be
13:07
there alone okay no problem pack now I'm going to run in this to see the result as you can see now we have this guy okay
13:14
pencil sketch converter that's good so the next thing that we need to create will be the labels for the preview okay
13:21
because we need to have uh previous for the original and the converted one so for that I'm going to do something like
13:27
this I'm going to C everything here okay give a little space and I'm going to paste oh I just run by mistake and this
13:35
I'm going to change this comment to previews
13:40
previews okay so this label let change its name
13:46
I'm going to call it like lore oh oh my God uh oh where is the l l
13:54
underscore preview preview underscore original
14:00
original because we are going to have like the original picture and the preview picture save and uh now let's
14:08
make some change here inside of the our label so uh here it will go to the frame
14:17
preview okay it's going to the frame preview and this guys will be
14:24
original original preview preview original preview okay
14:29
and uh for the font just let's decrease this one to two Okay will be 12 and we
14:35
don't need to make it bold okay let's remove bold and for BG we don't need to
14:42
change also the BG we can remove no I think okay let's keep it BG white itself
14:47
okay and FG let's change into three so after this okay after this change so now
14:54
let's come here so here instead of pack we are going to use place okay because
14:59
place is a very good place open and close and the hiden place okay we are going to use at X will be uh position 30
15:08
comma and for y will be equal 10 perfect so if we run this guy okay let's run it
15:17
contr b as you can see original okay so let's create another one for the converter so for the converter just
15:23
let's copy this guy copy go down and boom and here let's call it as a
15:29
converted the converted picture let's change to converted converted picture so
15:36
the converted one uh we just need to change it into converted okay converted preview
15:46
converted converted so converted and for the converted here let's change okay let's
15:52
change into 240 and let's keep 10 save and if I run let's see the results this
15:59
is the result that we got okay converter original and converted preview perfect
16:04
so the next thing that we need to do is to create the controls so for the controls let's go a little
16:11
down and let's comment here okay let's say controls controls per so uh for the
16:19
controls uh we need to create those control the first thing that we need to create will be the labels for the
16:25
controls and let's do something like this okay and
16:31
ttk ttk will be equal label okay open and close so let's uh
16:38
make put it inside of the frame control inside of frame controls comma
16:45
and the first one that we're going to create will be for the intensity so let's create text so text will be equal
16:53
let's do this intensity intensity intensity called comma
17:00
background okay so for the background of this one this intensity uh let's use
17:06
color one okay let's use Co one will be equal Co one co uh not comma okay let's
17:14
stop just like this okay and we'll build something like this itself then let's use dot
17:19
place place so let's use on X will be equal 10 comma and for y will be equal
17:26
oh will be equal 10 also perfect and so after this okay uh now
17:34
let's create the slice okay so for that let's create something like this s uh
17:39
intensity intensity s intensity uh will be equal let's create the
17:45
scale okay uh this scale will be inside of frame controls comma and let's do
17:54
something like this from underscore okay it will start on 50 comma and for the top the top that we
18:02
can use for the scale will be 300 okay then let's do this
18:09
comma and let's define also the orientation so for the orientation let's see something as oriented
18:15
Orient okay Orient because we can use this horizontal
18:21
horizontal horizontal comma and the length of it length so the length of it will be 200
18:29
comma and the BJ B we will change to the BJ of this so the BJ will be equal
18:36
co1 comma and FG will be equal Co 4
18:43
Perfecto so then after this uh let's use something like this intensity s
18:49
intensity dot set open and close oh my
18:54
mistake open and close let's use 120 and then let's do again s
19:02
intensity uh let's use Place do place open and close okay for X oh oh
19:10
that's not for X will be equal 10 on 10 and for y will be equal 30 I'm going to
19:18
save this and I'm going to run to see what I have as you can see we have the first scale okay which is this one it
19:24
start from 50 and end on 300 as we Define there okay perfect so this is for
19:30
the intensity so now we need to create for another ones which is those guys okay for the brightness and the contrast
19:37
so for that let's do something like this let me close this I'm just going to copy all this thing come here down okay boom
19:44
paste so the only thing that we need to change is the name okay I'm going to
19:50
come here come here and come here instead of intensity I'm going to call it for
19:56
brightness brightness okay then I'm going to come here inside Also let's write
20:05
brightness brightness perfect so brightness will start from 50
20:11
but it will end up on 200 only okay and uh for brightness let's set it to 100
20:20
only will be enough and it we need to change here from X uh we we will keep it
20:26
but for y let's keep it a little down now okay just use 100 save and uh if we
20:34
save and run let's see what we have now we have this guy okay but this uh we
20:40
forget the name of the label so for that we need to come here in this guy and come in the end here as you can see and
20:48
let's put it down to uh to 80 okay 80 will be enough 80 safe and if I run as
20:56
you can see intensity brightness yes perfect now one which is missing is is
21:02
the contrast so I'm going to copy this guy come down and paste so let's change
21:07
first this guy to contrast contrast
21:13
contrast and for the contrast here in the end it will go to 150 okay just
21:19
let's come here and let's put it 150 150 if I save this in if I run as
21:25
you can see we have contrast now let's create the scale for it so let's change
21:30
here let's call it contrast contrast save and if I run this
21:38
uh it's not showing because I need to change first this guy so let's down to
21:44
170 safe and uh here uh we we keep it in 200 so
21:50
50 to 200 no problem safe and if I run this guy as you can see now we have also contrast perfect we have everything so
21:58
so now which is remaining is those bottoms okay so we need to create the bottoms to choose the image and to save
22:04
the image this convert actually doesn't do anything okay I don't know why I put it there but because actually when I
22:10
click convert it's supposed to convert but since we are using this guys okay they scale so we don't need we don't
22:17
need to use it because it was supposed when I click here it will call the function to convert then it will convert
22:22
but since this guy when we slide it actually convert automatically now when
22:28
while we keep changing so we don't need this bottom but let's create them so for that it's
22:34
going to be something like this let's go a little down and let's create some botoms I'm going to comment here first
22:40
botoms botom botom go down then I'm going to create
22:46
beef underscore uh choose the first one is to choose the image it will be this
22:53
botom Bon will be open and is be inside of window itself uh window comma so
23:00
let's use test so the test the first test that we are going to have in this
23:05
side of those bottoms will be choose the first one is to choose choose image choose image come
23:14
here and give like a little comma then let's start Define the most important
23:19
things which is the BJ BJ will be for this one first one will be Co equal
23:25
one Co equal one comma not one six is better comma and FG will be equal uh co1
23:35
comma will be color white color and font for the font is going to be as always
23:42
Arial Arial and comma 10 so let's define
23:48
also the width no uh Arial 10 yes and come out of this comma and let's define
23:55
the width Al the width will be 50 in safe so for those botoms just like this
24:02
then let's come here let's call again B choose okay botom choose dot let's use
24:07
place and this gu is going to be something like this place what what we going to place we're going to place into
24:14
X will be on 20 comma and then after H
24:19
for y let's keep it a little down like 500 will be enough save and okay is
24:26
enough Okay then if I save this and if I run this guy boom as you can see we have the bottom to choose the image so now
24:32
let's create remaining bottom so the remaining one just let make use of this copy and paste and another guy also copy
24:38
and paste so H we just need to change it okay this is 20 and this guy is going to be to
24:47
160 160 and this guy will go to 300 okay
24:52
and to why why will keep because they will be in the same on in the same line then let's change the names also uh so
24:59
this guy will be convert come here and let's
25:04
convert so this is to convert the image and this one is to save the image let's
25:09
write it save okay if I save and if I run you can see all of them the same color but's change the colors and for
25:16
the first one let's change for this guy down one so this gun background will be five different color if i s run as you
25:23
can see is this guy so let's change this guy also so for that guy it will be two
25:30
save and if I run boom perfect as you can see now we finished with our UI okay
25:37
with the design so now let's make this thing working the first thing that we
25:43
are going to do is to create a function to choose the image okay because the first thing that we need to do is to
25:49
choose the image but the before that we need to Define some variables as uh
25:56
Global okay because there are some VAR that we need to use inside of the most of the functions so for that I'm going
26:02
to do something like this okay so I'm going to Define here on the top some variable as a global like the original
26:09
image okay because I need to know the path of the original image and even the
26:15
path of the converted image so that's why I'm going to do something like this okay let me say something like this
26:21
Global variables Global variables variables Global variables so I'm going
26:26
to do something like this global original original _ image original
26:33
uncore image comma and I'm going to uh to create another variable which is converted converted underscore image
26:42
okay these two variables will be Global so now let's uh Define let's initiate it
26:48
so I'm going to do something this original image is going to be equal n
26:53
even the converted one also converted image is going to be equal n
26:58
perfect so now the first image as I said now first we need to choose the image so in order to choose image let's get the
27:04
function okay let's comment here function function to
27:12
choose an image for to choose an image so for the that will be something like def choose def choose underscore image
27:21
So Def choose uncore image will be equal okay do come inside so let's define the
27:28
Global here okay inside Global the original image also so that we can manipulate they can have the same value
27:35
perfect so now let's the first that we need to do is to grab the path of the original image so let's do path will be
27:41
equal let's use the file dialog so that we can have option to choose the image follow di will be equal ask ask what ask
27:51
open file okay file name open and close so
27:56
this function this line okay help us to choose any any image okay then it will
28:02
keep the path of that image so after that let's do something this if path dot
28:09
if we get the path we can do something like this okay original image okay original image will be equal image
28:17
image. open okay open what get the path perfect so when we get the PA now let's
28:24
do something like this okay preview preview EMA image will be oh sorry will
28:29
be oh will be equal original image okay will be equal original image dot resize
28:38
like when we get do image okay we need to change it size so that it can show properly in our app so let's resize it
28:46
okay resize resize let's change it into uh
28:51
resize okay let open and close again 200 comma 200 okay so this is a very good
28:58
size to work with so after that uh so uh this is not fra frame
29:05
image okay uh it was supposed to be preview image not frame image I'm going
29:10
to create a new variable called preview image preview under score image this way
29:17
okay preview image perfect so now let's call this preview image again let's change again preview image will be equal
29:25
image okay now let's open it with t in okay image DK dot photo photo image
29:33
photo image equal equal what let's call this preview uh preview image again let's open it preview image save so
29:43
after that okay now let's show this image inide in our app so for that let
29:48
this lore preview image okay preview original image because we need to see the
29:55
original image will be called lot configure config this way config open and close I'm going to call
30:03
Image equal preview image okay image equal preview image I'm going to call
30:11
again okay this L preview original image
30:16
will be equal dot image okay I'm going to change now image will be equal
30:23
preview okay will be equal preview image perfect so this way we can preview our
30:29
image okay now if I save this so now in order to this to work we need to connect
30:34
this function into that bottom which is this guy okay the choose bottom uh oh
30:40
even here I forgot to change the names okay so this will be the choose bottom and this will be the
30:47
converted oh mistake change the name this will be
30:52
converted uh convert oh convert only it's enough and this guy will be for
31:02
save this is the save perfect so uh okay I'm going to commit
31:08
to the choose okay here I'm going to pass the command uh this command is wrong command
31:15
Okay command will be equal equal the choose image and comma okay save if I run this oh I made a
31:24
mistake uh original dot open original image oh oh I forgot to put equal here
31:31
so let me go to the line so it will be this line okay I'm going to use equal
31:36
okay this is where I forget to use equal okay save and let me run again boom okay
31:41
perfect so now if I click on my choose image see it open this option and I'm
31:47
going to choose that image neyar again this is neyar I click a neyar open and
31:52
boom as you can see now image of Neymar is showing okay so now we have the option to choose the image okay so now
32:01
the next option that we need to do okay uh we need to be able to convert this
32:06
image okay so in order to convert this image we need to create a function for that a function to convert the image so
32:13
for that we are going to do something like this so let me close this guy and come here down so below the diff uh
32:22
choose image function okay I'm going to come here and close this one so I'm going to
32:29
do something like this okay I'm going to create a function okay def
32:35
convert Dev convert image Dev convert image will be equal so is going to get
32:41
one event okay event will be equal non perfect and then let's put dot and come
32:48
inside so the first thing that we need to do is to declare those variable as a global again okay so these variables
32:54
these two we need to decare them as a global so I'm going to C copy just here and come here and boom paste perfect so
33:01
after that we do need to check if the original image is there or not so let's do something like this uh if original
33:10
or if original image okay is known okay
33:16
if it is empty or like nothing is there it is going to return it's going to end
33:22
this function okay so but if not let's do something like this okay and now the
33:27
first thing that we to do is I'm going to comment here do something like that user adjustment adjustment okay
33:34
adjustment so that we we know that we need to adjust those intensity and
33:39
brightness and contrast of the image okay so for that I'm going to do something like this first I'm going to create any something like this r equal s
33:47
for the in uh intensity okay s intensity do get okay we need to get the values
33:55
from the intensity okay then we need to get also the brightness so I'm going to
34:00
create a variable called brightness brightness so brightness will be equal
34:07
uh s brightness s brightness dot do what get
34:12
I'm going to get the value from the brightness and will be divided by 100
34:18
okay this the configuration that you need to end then the next one will be contrast so contrast also will be equal
34:23
a s contrast s a contrast dot get get what open and close come
34:31
here and boom underscore 100 okay
34:36
perfect so now the first thing that we need to do is to convert uh to pencil
34:41
okay first we need to convert it into pencil so to convert it into pencil we need to do something like this okay I'm
34:48
going to comment it and let's say convert
34:54
convert uh oh convert to pencil convert to pencil
35:01
sketch sketch this way okay I'm the first thing I'm going to create one varable called image okay underscore CV
35:08
will be equal okay I'm going to now use the open CV okay will be CV2 dot
35:16
CVT color okay open and close what CV2 again okay
35:23
do IM read okay this way in read open and
35:29
close what I'm going to read I'm going to read the original image okay it will be like we need to get the original
35:36
image dot do file name do
35:42
file name okay come here comma then let's use CV2 oh oh CV2
35:51
dot color everything Capital color underscore
35:58
BG R to gray okay we need to convert
36:03
into gray so that it can look like a pencil okay like something that was drawn by pencil okay perfect so now uh
36:12
after this okay we need to use some blue on it let's use some blue on it so blue what blue CV2 again
36:20
dot g this way okay gaan Gan blue open and close why I need
36:29
to what in what I'm going to use I'm going to use the image image CV comma open and close 21
36:37
this is the configuration comma 21 okay come out vew comma and zero perfect so
36:46
now let's use another one okay sketch will be equal
36:52
CV2 do divide okay do divide divide but open
36:58
and close EMG underscore CV comma
37:04
blue comma scale what I'm going to use for scale I'm going to use the r for the
37:10
intensity okay will be equal R okay so that mean the r will help us to
37:18
change perfect so now the thing that we need to do now is to connect this
37:25
function H to that scale okay so in order to do that okay uh we need to go
37:31
down to the scale to the intensity and we need to use the command there okay so
37:37
I'm going to go inside of the intensity so this is the intensity okay I'm going
37:42
to come here oh no scale here okay then I'm going to use the command will be
37:49
equal equal what equal convert image comma this way okay so I'm going to copy this guy again
37:55
also copy it and and I'm going to come here okay
38:00
for here for the brightness also I'm going to do the same thing
38:06
paste so I'm going to look for the contrast the same thing paste okay perfect so now let me
38:13
run and boom I think I got some kind of error I can see here there is er it said
38:19
name or is not defined did you mean or what is it and line 43 if or Oh no I got
38:26
it so it was supposed to be original if original original image it's supposed to
38:33
be this one okay save let's run again boom perfect so let's choose an image
38:39
let's choose name it again okay now intensity is connected if I change this
38:45
uh nothing is happened what about this guy nothing also even this nothing so now let's see
38:52
what is missing why is not working okay because uh I think it's because of the the convert converted is supposed to
38:58
show but it's not showing so it means let's try to figure
39:04
out this play side okay because original is not going to change we need to change
39:09
the converted one so for that we need to do something like this so I'm going to
39:14
close this guy and I'm going to come here okay oh this guy was supposed to be
39:20
convert this and I'm going to come a little down and I will say something like this see I
39:27
have a converted pencil so I'm going to do something like this okay I'm going to call create a variable called converted
39:34
image convered underscore image will be equal
39:41
um pencil okay uh will be equal pencil sketch okay
39:47
pencil underscore sketch okay but this pencil underscore sketch we don't have
39:53
it yet okay so that means first I'm going to come here up I'm going to create that variable okay so for that
39:59
I'm going to do something of this I'm going to comment here I'm going to say adjustment
40:04
adjust brightness brightness and contrast so this will be
40:13
for the brightness and contrast so I'm going to create a variable called pencil sketch so this pencil sketch will be
40:18
equal image Dot from okay from
40:24
aray this way open close what I'm going to do I'm going to send this image here
40:30
the sketch okay sketch boom perfect so after that let's do for the brightness
40:37
so for the brightness some of this brightness okay brightness underscore a
40:43
yes and yes this way okay answer brightness and answer will be equal
40:50
image and this way dot brightness dot brightness right next
40:58
this way open close what I'm going to send I'm going to sell the pencil sketch
41:04
okay I'm going to send penil sketch there inside so after
41:09
this okay uh I'm going to create another variable again called like pencil sketch
41:17
will be equal will be equal brightness okay will be equal
41:23
brightness brightness okay brightness and answer
41:29
okay which is this variable that we created on the top brightness and answer
41:39
dot this way what open and close what we're going
41:44
to brightness okay brightness we need to send the brightness here
41:53
bright brightness this way perfect okay which is this brightness so that will help us to change this thing perfect so
42:00
after that now let's do for the uh contrast okay so but before this since
42:08
we have this guy okay uh now let's continue converted image will be equal this guy then let's do something like
42:14
this okay preview uh preview image will be equal converted image converted image do
42:24
resize resize open and close close open and close again let's use 200 comma 200
42:32
okay then let's create another image again preview image again will be equal
42:39
emj TK do F image okay what's going to open we are
42:46
going to open the preview image perfect now let's send it into the label so
42:52
let's see lore preview converted okay dot
42:59
config open and close let's say image okay we need to change the property of the image will be equal the preview
43:06
image perfect and then let's do again
43:12
lore converted do image will be equal
43:17
review image okay save now let's run this to check okay let's choose an image
43:24
name are and if I do for intensity boom I got some error okay even for
43:30
brightness error contrast nothing will happen error so so let's see what is the error that weting by intensity he
43:39
said uh function doesn't object okay resize
43:44
resize uh object has no attribute resize where is preview image equal convert
43:52
image preview image on the line 63 so let's go down the line seity uh convert
43:59
ah it's supposed to be this image converted image I wrot it convert image so that's why okay let's change this
44:07
save and let's run again okay perfect so uh image first Nar
44:14
let's change intensity okay perfect now it's working as you can see okay if I
44:19
change the brightness the brightness also is working as you can see okay zero
44:26
okay brightness bright brightness even the brightness Now is working now for the contrast contrast is
44:32
not applied yet so now let's let's do now let's do this one okay the contrast one so for that uh let's come
44:39
down where are we okay we are here okay uh if I come here after this
44:46
just go down and for the contrast let's create a variable called
44:51
contrast contrast uncore inan answer and answer
44:58
will be equal uh after that so we just need to do something like image and yes
45:04
again uh do contrast let's open and close and let's
45:10
call again the pencil sketch pencil penil sketch save and uh after
45:17
this we need to call pencil sketch again pencil sketch will be equal
45:23
contrast contrast uncore uh blah blah blah oh oh I think I made a mistake now okay
45:30
is correct contrast in answer answer I always forget this R answer will be
45:37
equal open and close let's send the contrast because the contrast one is the
45:43
one is going to help us to change which is this one okay now let's save and run
45:48
to see if it's going to work or not okay we have this one first choose the image
45:54
and we choose this guy so for intensity or oh again a mistake so let's check uh
46:00
this guy name error contrast any answer is not defined you mean contrast any
46:05
answer uhuh exactly 61 I did a mistake so let's go to the 61 here contrast and
46:14
answer it's supposed to be this one contrust contrust and
46:23
answer and this guy bye-bye okay if I S this guy uh okay now it's
46:30
work save and run choose the image neyar
46:35
okay if we change this intensity again the same thing uh contrasts object has
46:41
no attribute okay contrast contrast
46:47
contrast contrast where is the error did you mean uh which line 61 contrast do ah
46:57
supposed to be contrast
47:03
do H where is the mistake ah is this one I forget and save
47:12
and let me run again choose the image Nar okay if we change this okay
47:21
now it's working perfectly so for the brightness exactly good and for the contrast and good as you can see even
47:28
the contrast is working so now everything is worked so the next thing that we need to do only is to create the
47:33
function so that we can save this image okay the converted image so for that will be this buttons so let's do
47:39
something like this let me put down that guy and come here so below this function
47:45
here let's create a new function so that is going to be something like this so uh
47:51
let's uh create a function called def save image savecore e image is going to
47:58
be something like this open and close Dot and boom so first let's check if the converted image is there or not okay
48:04
let's do something if converted if converted undor image dot
48:12
let's do something is pa okay equal file dialog do ask save ask save as file
48:25
name name oh name underscore what
48:31
default uh default default default test text this
48:39
way default text uh text extension
48:46
text then okay default this name is very
48:51
complicated so H default default text
48:57
extension text extension or extension not Le extension will be equal okay so
49:04
we want to save it as a PNG so let's use PNG okay comma file type
49:12
file file type file types is going to be
49:18
so here we can give like a list and Define which type that we need it to be
49:24
so it can be something like this okay so uh open a to and first let's give
49:31
something like PNG okay PNG files the only file that we
49:36
want to see when we open that one PNG Files come here comma and let's do
49:43
something like this and any type also okay any type of PNG
49:48
PNG and after this come open and close and let's say something like this
49:54
all files
50:01
all F okay comma then let's do something like this and again all dot all okay for
50:08
all type of the files perfect so uh after this okay we need to come here down oh oh mistake just let me come here
50:16
and boom enter okay it's going to keep me here okay perfect so if PA
50:23
dot do something like this converted converted image dot Save open what in
50:32
the path that we going to uh choose save and now let's connect this save image to
50:38
the bottom okay save image uh where is the bottom bottom to save this guy so
50:44
come here let's give command will be equal save image and boom save and
50:51
run okay now let's test the final test choose image
50:57
if I do intensity blah blah okay perfect I like this one okay if I click on save
51:02
image okay now let's choose any place so where can I choose so let's see in the download itself okay let's give uh
51:11
neyar
51:16
TTP save and boom I think it's save okay let's go there into the downloads
51:21
download folders ah there is Neymar TT so if I open this guy as you can see our
51:28
app is working perfectly okay so so guys this is the end of the tutorial okay
51:35
thanks for being here with me so if you like this tutorial please give a like to the video and subscribe even share the
51:42
video so if you want to support me so I'll keep some description in the some links okay in description of this video
51:49
so you can support me because even me I'm fighting to get a new laptop this one is dying completely so if you want
51:55
to support me so there is a link so you can support me and thank you see you in the next video okay next I'm kind of
52:01
tired bye-bye

