Create an art or image by yourself using arrays and Numpy

Create an art or image by yourself using arrays and Numpy


Creating art with NumPy involves using the NumPy library in Python to generate visual patterns, images, or designs. NumPy provides a powerful array manipulation library that allows for efficient handling and manipulation of multi-dimensional arrays.

Here’s a brief introduction to creating art with NumPy:

  1. NumPy Arrays: NumPy arrays are the core data structure used in this process. These arrays can represent images, patterns, or any kind of visual data. They are efficient for numerical operations and can be easily manipulated to create different visual effects.
  2. Generating Patterns: NumPy can be used to generate a wide range of patterns, from simple geometric shapes to complex, intricate designs. This can be achieved by manipulating the values within the NumPy array.
  3. Color Manipulation: By assigning different numerical values to elements in the NumPy array, you can control colors and create gradients, allowing for the generation of colorful and visually appealing art.
  4. Mathematical Functions: Mathematical functions can be applied to the elements of the array to create more complex patterns. For example, using trigonometric functions like sine and cosine can lead to interesting visual effects.
  5. Image Processing: NumPy can also be used for image processing tasks. You can load, modify, and save images using NumPy, allowing for creative manipulation of photographs or other visual content.
  6. Visualization Libraries: While NumPy provides the foundation for generating art, visualization libraries like Matplotlib or OpenCV are often used to display the resulting images or patterns.

Overall, creating art with NumPy is a versatile and creative endeavor that leverages the power of numerical computation to generate visually appealing designs. It’s a popular approach for artists, data scientists, and hobbyists alike who want to explore the intersection of mathematics and art.

Let's dive into an art completely done with Numpy arrays,

Also, I have used OpenCV, Here is Why?


OpenCV (Open Source Computer Vision Library) primarily focuses on computer vision tasks like image processing, object detection, and more. While it’s not primarily designed for creating diagrams, it can be used in combination with other libraries to generate visual representations. Here are a few ways OpenCV can be used to create diagrams:


Custom Diagram Generation:

  • OpenCV can be used in combination with other Python libraries like NumPy and Matplotlib to generate custom diagrams. For instance, you can use NumPy to create arrays representing shapes and then use OpenCV to render them.
  • Geometric Shapes: OpenCV provides functions to draw geometric shapes like lines, rectangles, circles, and polygons on images. These shapes can be combined to create diagrams.
  • Contours: OpenCV can be used to find contours in images, which can then be used to draw boundaries around objects. This can be useful for creating diagrams in computer vision applications.

Art Image:

  1. Import the Python Library Modules for the creation of the art

import cv2
import cvzone
import numpy as np        


2. Art created using the arrays and Numpy


width = 400
height = 300
img = np.zeros((height, width, 3), np.uint8)
  
# Three vertices(tuples) of the triangle 
p1 = (90, 90)
p2 = (50, 150)
p3 = (150, 150)

img[225:600] = [0, 242, 24]
img[0:150] = [235, 205, 125]
img[180:225]=[244,242,236]

cv2.circle(img, (300,80),30,(0,167,255),cv2.FILLED)
cv2.circle(img, (300,80),30,(0,167,255),cv2.FILLED)
#width,height
# Format: (startY:endY, startX:endX)
cv2.rectangle(img, (50,150), (150,230), (57,237,255),cv2.FILLED)
cv2.rectangle(img, (80,180), (115,230), (246,71,211),cv2.FILLED)

# Drawing the triangle with the help of lines
# on the black window With given points 
# cv2.line is the inbuilt function in opencv library
cv2.line(img, p1, p2, (255, 0, 0), 3)
cv2.line(img, p2, p3, (255, 0, 0), 3)
cv2.line(img, p1, p3, (255, 0, 0), 3)
  
# finding centroid using the following formula
# (X, Y) = (x1 + x2 + x3//3, y1 + y2 + y3//3) 
centroid = ((p1[0]+p2[0]+p3[0])//3, (p1[1]+p2[1]+p3[1])//3)

# Drawing the centroid on the window  
cv2.circle(img, centroid, 0, (244, 233, 219),cv2.FILLED)
# image is the title of the window
cv2.imshow("image", img)
cv2.waitKey(10000)
cv2.destroyAllWindows()        

Output:



Avnish Kumar Thakur

Kubernetes, DevOps & Networking Expert | Solving Complex Infra Challenges | Building Scalable & Resilient Cloud Systems

1 年

Nice work ??

回复

Nice!? You might be interested in joining our platform, TheWide - a brand new social network for coders & developers. Connect, collaborate, exchange ideas, and *share code directly to your feed* ?? Also, it's totally FREE ??, so come check us out at https://thewide.com/ ?

回复

要查看或添加评论,请登录

Prateek Mudgal??的更多文章

社区洞察

其他会员也浏览了