Found 10805 Articles for Python

Quickly convert Decimal to other bases in Python

AmitDiwan
Updated on 11-Aug-2022 11:31:07

1K+ Views

To quickly convert Decimal to other based, we will be using the Built-in functions in Python − Decimal to Binary − bin() Decimal to Octal − oct() Decimal to Hexadecimal − hex() Decimal number system has base 10 as it uses 10 digits from 0 to 9. In decimal number system, the successive positions to the left of the decimal point represent units, tens, hundreds, thousands, and so on. Binary uses two digits, 0 and 1. Also called as base 2 number system Each position in a binary number represents a 0 power of the base (2). Last ... Read More

Implementing Photomosaics in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

525 Views

The photomosaic is a technique, where we can split our image into a grid of squares. Each square will be replaced by some other images or colors. So when we want to see the actual image from a certain distance, we can see the actual image, but if we come closer, we can see the grid of different colored blocks. In this case we are using a Python module called photomosaic. Using this module, we can easily create some photomosaics. To install it please follow this link. It will also download the scikit learn module. sudo pip3 install photomosaic ... Read More

Generating Random id's using UUID in Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

665 Views

UUID is having the full form Universal Unique Identifier, it is a python library which supports 128 bits ids for generating random objects. Advantages of UUID As discussed, we can use it to generate unique random id for random objects. For cryptography and hashing applications, this id can be used. For generating random documents and also addresses etc. this id can be used. Method1 Using uuid1() Example code import uuid print ("Random id using uuid1() is : ", end="") print (uuid.uuid1()) Output Random id using uuid1() is : 4adeede2-e5d8-11e8-bd27-185e0fd4f8b3 Representations of uuid1() bytes − ... Read More

Addition and Blending of images using OpenCv in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

332 Views

We know that when we solve any image related problem, we have to take a matrix. The matrix content will vary depending upon the image type - either it would be a binary image(0, 1), gray scale image(0-255) or RGB image(255 255 255). So if we want to add of two images then that means very simple we have to add respective two matrices. In OpenCV library, we have a function cv2.add() to add the images. But for image addition the size of the two images should be same. Addition of two images import cv2 # Readingour Image1 my_firstpic ... Read More

Histograms Equalization using Python OpenCv Module

Samual Sam
Updated on 30-Jul-2019 22:30:23

535 Views

This is a method in image processing to do contrast adjustment using the image's histogram. Actually this method usually increases the global contrast of many images, especially when the usable data of the image is represented by close contrast values and through this adjustment, the intensities can be better distributed on the histogram and it allows for areas of lower local contrast to gain a higher contrast. OpenCV has a function to do this, cv2.equalizeHist() and its input is just grayscale image and output is our histogram equalized image. This technique is good when histogram of the image is confined ... Read More

Dunder or magic methods in python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

346 Views

magic methods that allow us to do some pretty neat tricks in object oriented programming. These methods are identified by a two underscores (__) used as prefix and suffix. As example, function as interceptors that are automatically called when certain conditions are met. In python __repr__ is a built-in function used to compute the "official" string representation of an object, while __str__ is a built-in function that computes the "informal" string representations of an object. Example Code Live Demo class String: # magic method to initiate object def __init__(self, string): ... Read More

Reading an image using Python OpenCv module

Samual Sam
Updated on 30-Jul-2019 22:30:23

2K+ Views

In OpenCv module, we can use the function cv2.imread() to read an image. When inputting the image path, the image should be in the working directory or a full path of image should be given. cv2.IMREAD_COLOR − This function loads a color image and any transparency of image will be neglected. It is the default flag. cv2.IMREAD_GRAYSCALE − This function loads image in grayscale mode cv2.IMREAD_UNCHANGED − This function loads image as such including alpha channel Source Image Example import numpy as np import cv2 my_img = cv2.imread('C:/Users/TP/Desktop/poor/poverty_india.jpg', 0) cv2.imshow('image', my_img) k = cv2.waitKey(0) & 0xFF # wait ... Read More

Draw geometric shapes on images using Python OpenCv module

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

1K+ Views

The basic operations of OpenCV is to draw over images. The ability to add different geometric shapes just like lines, circles and rectangle etc. Often working with image analysis, we want to highlight a portion of the image, for example by adding a rectangle that defines that portion. Also as example an arrow to indicate something. cv2.line() − This function is used to draw line on an image. cv2.rectangle() − This function is used to draw rectangle on an image. cv2.circle() − This function is used to draw circle on an image. cv2.putText() − This function is used to write ... Read More

Rename multiple files using Python

AmitDiwan
Updated on 24-Aug-2023 14:24:44

46K+ Views

To rename files in Python, use the rename() method of the os module. The parameters of the rename() method are the source_address (old name) and the destination_address (new name). Install and Import the OS module To install the OS module − pip install os To import − import os Rename multiple files using rename() method The rename() method can be easily used to rename multiple files − Example import os # Function to rename multiple files def main(): i = 0 path="E:/amit/" for filename in os.listdir(path): my_dest ="new" + str(i) + ".jpg" my_source =path + filename my_dest =path ... Read More

Color game using Tkinter in Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

1K+ Views

For developing GUI applications tkinter is very popular and easy. Using tkinter easily develop GUI games. Here also we are trying to develop color game. In this game the player has to enter color of the word that appears on the screen and hence the score increases by one, the total time to play this game is 30 seconds and colors used in this game are Red, Blue, Green, Pink, Black, Yellow, Orange, White, Purple and Brown. The interface will display name of different colors in different colors. User has to identify the color and enter the correct color name ... Read More

Advertisements