DICOM images in Python

DICOMs format is used to store CT-Scan or MRI images, DICOMs contain header information and multidimensional images array. The header normally contains patient information and information about DICOM images.

These images from CT-Scans or MRI contain density values that are stored in images, instead of colors such as RGB or Grayscale, we have Density values between -3000 to +3000. these images have width and height just like any other image, but there can be more than one of these images in a single DICOM file. These images are slices obtain from CT-Scan or MRIs of a patient from different places, such as CT-Scan machine moving up or down and taking images using X-rays.

In CT-Scan these Density values have units of HU, where 0 is water, 200 to 1000 are bones and 2000+ are metals. below zero is air.

Introduction to Deep Learning

 

Introduction to Deep Learning

 

In past centuries, if someone told you that a machine can behave like you and perform your tasks, you would probably laugh at this absurd statement. However, today people use this technology in many aspects of their lives. We now know this technology as deep learning.

In this article, you will learn all you need about deep learning, how it works, the difference between deep learning and machine learning, its application, and lastly careers in deep learning.

What is Deep Learning?

Deep learning is the subdiscipline of the extensive field of machine learning. This technology imitates the way the human brain functions. It acts, learns, and makes decisions similar to an actual person but with higher accuracy. It does so with the help of artificial neural networks.

Artificial neural networks take the role of neurons of a brain. That is why some also call them artificial neurons. It has several layers, each performing complex action. It has nodes and neurons to perform input and output operations.

How Does Deep Learning Work?

To know how machine learning works, just picture an animal brain at its work. What do you see? Probably billions of neurons send and receive signals to perform each task. A brain has billions of neurons that work tirelessly to send and receive information and to make decisions.

In a similar way, artificial intelligence has nodes in place of neurons. These nodes are interconnected and form three layers.

·       Input Layer

The first layer is the input layer. It functions as the name suggests. It receives data and then decides what to do with this information.

·       Hidden Layer

The next layers are the hidden layer. These perform the principal functions of deep learning and thus are several in number. This layer receives all the necessary information from the input layer. It then performs complex mathematical operations on it. It performs all the learning, image processing, facial recognition, and other similar tasks.

·       Output Layer

The hidden layer converts the data into output. It sends it to the output layer. The output layer is the last layer of the artificial neural network. It provides the answer to your questions in addition to making predictions.

Difference between Deep Learning and Machine Learning

As established above, deep learning is the subfield of machine learning. Now, let's learn what is the difference between these two fields. Before that, let us first revisit the concept of machine learning.

Machine learning deals with computers and their algorithms. Its main function is to help the computer learn from a specific set of data. The computer then performs tasks and makes decisions based on this analysis. All that is done without any use of complex programming methods.

On the other hand, deep learning does not work in a machine-like manner, unlike machine learning. It performs more sophisticated human-like functions.

Deep learning and machine learning has the following key differences:

1.     Human Supervision

Machine learning is usually unable to provide the end results on its own. It requires regular human intervention in order to do so.

Whereas, deep learning does not need that much supervision to perform its tasks.

2.     Efficiency

Deep learning provides more efficient results but it takes more time to operate.

On the other hand, machine learning needs less time to operate but the results will not be that productive.

3.     Data Processing

Deep learning and machine learning are also dissimilar in the way they take and process data. Machine learning uses long-established operations to process structured data. Whereas, deep learning uses artificial neural networks to process even unstructured data.

Applications of Deep Learning

Artificial Intelligence and deep learning are all the rage these days. Whether you are aware of it or not, the deep learning technology has already found its use in multiple devices you own.

Here we have listed some of the most common applications of deep learning:

·       Automated Cars

Out on the roads, you may have seen at least a few self-driving cars. Ever wondered how they work? An automated vehicle is a concept that has been made possible with the help of deep learning.

It is also used in automobile industries to improve safety measures.

·       Healthcare Facilities

This technology has far greater precision than a human. That is why healthcare facilities have started using this innovation. Cancer detection is a difficult task. But with the help of deep learning, it has become easier than ever.

·       Online Shopping

You may get surprised sometimes when you see an advertisement for something you need on your home page. Or when a website starts providing personalized recommendations for you. These e-commerce platforms also use deep learning to increase sales.

·       Home Assistant

You can find deep learning in electronic devices such as translation devices or home assistants. Call out to your home assistance device and it will respond and assist you.

·       Safeguarding

Deep learning can be of great help in war-like situations. It will recognize the danger in any area and help evacuate people.

It can also predict risky situations such as earthquakes.

Careers in Deep Learning

Undeniably, deep learning is a very interesting field with a vast set of applications. If you are interested in computer software, problem-solving, and artificial intelligence, then this might be the right field of study for you.

After learning about this technology, you can go for various career paths. We have listed some of them below:

1.    Data Engineer

It is a field that uses all kinds of science including biomedical science. You will also need the knowledge of programming languages to excel in this field. Data engineers build programs to collect data and interpret it.

2.     College Professor

If you want to go for the teaching profession, you can choose to pursue a Ph.D. degree in this field. This way you will easily find a job as a college instructor.

Deep learning is a field that will have a great impact on future generations. That is why it needs talented people to make progress and change peoples’ lives.

 

 

 

Generate 3D Terrain in python using random noise and marching cube

Generate 3D Terrain in python using random noise and marching cube


import numpy as np
from skimage import measure
from scipy.ndimage import interpolation
import os
import bpy

# noise = PerlinNoise(octaves=4, seed=3)


# Step 1
def generate_random_3d_array() -> np.ndarray:
    """generate 3d numpy array

    Returns:
        np.ndarray: [description]
    """
    # for every x and y there should be certain z value
    width = 10
    length = 10
    height = 6
    # all ones 3d array
    chunk = np.ones((width, height, length))
    for x in range(width):
        for z in range(length):
            # random height for our 3D terrain
            y = np.random.randint(1, 4)
            chunk[x, :y, z] = 0
            # all values below our height will be Zeros

    chunk = chunk.astype("uint8")

    # use interpolation to change scaling of 3D object
    # increasing scale factor will smooth the 3D terrain
    scale = (10, 2, 10)
    chunk = interpolation.zoom(chunk, scale)
    # print(chunk)
    return chunk


# TODO Create Cave in 3D Terrain
def create_cave(chunk: np.ndarray) -> np.ndarray:
    """[summary]

    Args:
        chunk (np.ndarray): [description]

    Returns:
        np.ndarray: [description]
    """
    chunk[20:60, 1: 5, 11: 35] = 1
    chunk[45:55, 5: 10, 25: 30] = 1  # CAVE Entrance
    return chunk


def save_obj(vertices, faces, normals, path: str, name: str):
    """Save 3D Terrain as obj file

    Args:
        vertices ([type]): [description]
        faces ([type]): [description]
        normals ([type]): [description]
        path (str): path of the new file
        name (str): name of the new file
    """
    faces = faces + 1  # Make Indexes of vertices start from 1

    with open(os.path.join(path, name)+".obj", 'w') as newObj:
        for v in vertices:
            newObj.write("v {0} {1} {2}\n".format(v[0], v[1], v[2]))

        for n in normals:
            newObj.write("vn {0} {1} {2}\n".format(n[0], n[1], n[2]))

        for f in faces:
            newObj.write("f {0}//{0} {1}//{1} {2}//{2}\n".format(f[0],
                                                                 f[1],
                                                                 f[2]))


def smart_uv_unwrp(name: str) -> None:
    """UV Unwrap for texture using blender

    Args:
        name (str): name of saved obj file
    """
    file_loc = os.path.join("obj", name)+".obj"

    obj_object = bpy.ops.import_scene.obj(filepath=file_loc)
    obj_object = bpy.context.selected_objects[0]

    if obj_object.type == 'MESH':
        # bpy.context.scene.objects.active = obj_object
        bpy.ops.object.editmode_toggle()  # entering edit mode
        bpy.ops.mesh.select_all(action='SELECT')  # select all objects elements
        bpy.ops.uv.smart_project()  # the actual unwrapping operation
        bpy.ops.object.editmode_toggle()  # exiting edit mode
        bpy.ops.export_scene.obj(filepath=file_loc)


def generate_random_chunk(name: str) -> None:
    random_3d = generate_random_3d_array()
    # random_3d = create_cave(random_3d)

    # Use marching cubes to obtain the surface mesh of these ellipsoids
    # Marching cube will convert numpy array to 3D Terrain
    verts, faces, normals, values = measure.marching_cubes(random_3d, 0)

    # save obj
    save_obj(verts, faces, normals, "obj", name)

    # load obj in blender and convert obj uV unwrap using blender
    smart_uv_unwrp(name)


name = "land2"
print("Creating Random 3D terrain")
generate_random_chunk(name)
print("Done")

Voice Changer in Python

This is python code to change voice, first, it converts your voice to text, next it converts text to speech.

Requirements.txt

SpeechRecognition
pyttsx3

Speech to text

import speech_recognition as sr


r = sr.Recognizer()

with sr.Microphone() as source:
    # read the audio data from the default microphone
    print("Recognizing...")
    while True:
        # r.adjust_for_ambient_noise(source)
        audio_data = r.listen(source)
        # convert speech to text
        try:
            text = r.recognize_google(audio_data)
            print(text)
        except sr.UnknownValueError:
            pass

Text To Speech

import pyttsx3

converter = pyttsx3.init()

voice_id = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0"
# voice_id = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_DAVID_11.0"
converter.setProperty('voice', voice_id)

# Sets speed percent Can be more than 100
converter.setProperty('rate', 150)
# Set volume 0-1
converter.setProperty('volume', 0.7)

while True:
    text = input()
    converter.say(text)
    converter.runAndWait()

Voice Changer

import speech_recognition as sr
import pyttsx3

r = sr.Recognizer()

# combine both speech to text and text to speech

converter = pyttsx3.init()

voice_id = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0"
# voice_id = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_DAVID_11.0"
converter.setProperty('voice', voice_id)

# Sets speed percent Can be more than 100
converter.setProperty('rate', 150)
# Set volume 0-1
converter.setProperty('volume', 0.7)


with sr.Microphone() as source:
    # read the audio data from the default microphone
    print("Recognizing...")
    while True:
        r.adjust_for_ambient_noise(source, duration=0.2)
        audio_data = r.listen(source)
        # convert speech to text
        try:
            text = r.recognize_google(audio_data)
            # text = r.recognize_sphinx(audio_data)
            print(text)
            converter.say(text)
            converter.runAndWait()
        except sr.UnknownValueError as e:
            pass

Building a CLI-Based People Tracking and Dwell Time Analytics System Using YOLOv8 and DeepSORT

  Introduction Tracking people across video frames and analyzing their behavior (like  dwell time ) is a crucial task for many real-world ap...