nsvision - Computer Vision Wrapper built on top of PIL, cv2 and Numpy
Project description
nsvision
This wrapper library is built on using PIL , cv2 and Numpy.
We have optimised the library for reducing the code work while working on image processing for data science.
nsvision functions:
-
imread(image_path) #Reads an input image and returns 3d image array
-
imshow(numpy array) #Opens up a new window and displays in new window
-
imsave(path) #Save image from array to a specific path
-
expand_dims(numpy_array) #expand array dimensions based on axis position
-
reduce_dims(numpy_array) #reduce image dimensions based on axis position (must use if expand_dims is called on image, before displaying or saving image)
-
imsave(array) #save image to location
-
live_video #run this function to display live stream from webcam, you can also add your model_function as input (mostly used for object detection)
Installation:
pip install nsvision
Usage:
Python
- importing
import nsvision as nv
- Reading an image for model
- Reading from path
image_array = nv.imread("image_path", resize = (224,224), color_mode='rgb')
#function returns image as numpy array
- Reading from url
#Get image from url
image = nv.imurl('https://example.com/example_image.jpeg')
#Get image array from url
url = 'https://example.com/example_image.jpeg'
image_array = nv.imurl(url,return_as_array=True,resize=(150,150), color_mode = 'rgb')
- Display image (terminal / jupyter)
#displaying a regular image
nv.imshow(image_array)
#displaying image read from cv2 function
nv.imshow(image_array , is_cv2_image = True)
#setting is_cv2_image = True , will display image read from cv2.imread()
- Saving an image.
#saving regular image
nv.imsave('path_to_write_image' , image_array , file_format='png')
#saving image read from cv2 library
nv.imsave('path_to_write_image' , image_array , file_format='png', is_cv2_image = True)
- Expand Image Dimensions
#expand image dimensions as per axis position
expanded_image = nv.expand_dims(image_array, axis = 0)
#expand image and normalize
expanded_normalized_image = nv.expand_dims(image_array,normalize = True)
- Reduce Image Dimensions
reduced_image = nv.reduce_dims(image_array, axis = 0)
- Live Video Streaming
nv.live_video(source=0, color_mode = 'rgb', resize=(224,224))
- Encode image to Base64 String
nv.image_to_base64(image_from_array,file_format='PNG')
#encodes image as base64 string.
#Mostly helpful for sending image to API (Tensorflow Serving)
#Can be used for production
- Decode Base64 Image String
decoded_image_bytes = nv.base64_to_bytes(base64_encoded_image)
#decode base64 image string and convert to bytes. Later on you can use nv.imread(decoded_image_bytes)
- Image splitter using directly in jupyter notebook
from nsvision import classifier
classifier.split_image_data(
data_dir = "images/cats_vs_dogs",
ratio=(40,30,20,10))
#splits images from given folder as per train, val , test and QA.
#Mostly helpful for image classification problems
#opens a window showing video from source , source 0 is webcam
#### Using nv.live_video() for object detection / live image classification
```python
#create your preprocessing function which accepts image_array as input and returns processed image_array
#sample preprocess function which can be used with nv.live_video()
def pre_processing_function(image_array):
#your preprocessing steps here
#example:
image_array = nv.expand_dims(image_array,axis=0,normalize=True)
prediction_boxes = model.predict(image_array)
image_array = draw_boxes(image_array,prediction_boxes)
return image_array #note your preprocessing function must return image array as output, or it will throw error.
Command line (split data script)
Use commandline tool for splitting data as per ratio for image classification problems
- Syntax
split_data -d path_to_data_folder -r ratio_in_tuple_string
- example
split_data -d "./cats_vs_dogs" -r "(70,10,10,10)"
This will split data inside class folder as 70% for training , 10% validiation, 10% testing and 10% for QA.
For more information about using command line tool:
split_data -h
Command line (rename files script)
Use commandline tool for renaming the files in a folder
- Syntax
rename_files -n common name -f folder path -i number from which renaming to be started
- example
rename_files -n "image_" -f "./image_folder" -i 1
This will rename the files in the image_folder
For more information about using command line tool:
rename_files -h
Command line (tumor data extractor script)
Use commandline tool specifically for extracting and converting the mat files of brain tumor image data from the downloaded zip file using this link
- Syntax
tumor_data_extractor -b folder path of the downloaded zip folder -e extension in which mat files to be converted(default - jpg)
- example
tumor_data_extractor -b "./1512427.zip" -e png
This will convert all the .mat file in the above zip folder into the given extension file format(default .jpg) All the converted files will be save in separate folder named brain_tumor_data in their respective tumor name folder
For more information about using command line tool:
tumor_data_extractor -h
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for nsvision-0.0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80642fe14c21502c87120c90dbcc19e6d7e105aa92b66c219c4e82ec662d0bde |
|
MD5 | 7924aa21f18f72d07b4761c340a2ba95 |
|
BLAKE2b-256 | 0044d5ac6f74552a21fe8a37d4a05868d31d6d6bf1d5d58a5438369671d5855a |