Found 34494 Articles for Programming

Implementing Photomosaics in Python

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

544 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

How to obtain the highest occurring character in a String using C#?

George John
Updated on 26-Jun-2020 14:33:01

3K+ Views

The highest occurring character in a string is one that occurs most number of times. This can be demonstrated using the following example.String: apples are red The highest occurring character in the above string is e as it occurs 3 times, which is more than the occurrence of any other character.A program that obtains the highest occurring character in a string using C# is given as follows.Example Live Demousing System; namespace charCountDemo {    public class Example {       public static void Main() {          String str = "abracadabra";          int []charCount = ... Read More

Generating Random id's using UUID in Python

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

701 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

342 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

558 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

364 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

2K+ 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

48K+ 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

How to create a static class in C++?

Arjun Thakur
Updated on 13-Apr-2023 00:15:52

21K+ Views

There is no such thing as a static class in C++. The closest approximation is a class that only contains static data members and static methods.Static data members in a class are shared by all the class objects as there is only one copy of them in the memory, regardless of the number of objects of the class. Static methods in a class can only access static data members, other static methods or any methods outside the class.A program that demonstrates static data members and static methods in a class in C++ is given as follows. Example #include ... Read More

Advertisements