Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

generate binay image python

import numpy as np
from numpy import random

# Generating an image of values between 1 and 255. 
im_thresh = random.randint(1,256, (64,64))

# Set anything less than 255 to 0. Unnecessary if cv2 does this during threshold. 
# Must go before the operation below in order not to set all values to 0. 
im_thresh[im_thresh<255] = 0

# Set all values at indices where the array equals 255 to 1.
im_thresh[im_thresh==255] = 1
Comment

PREVIOUS NEXT
Code Example
Python :: python save dictionary 
Python :: odd or even python 
Python :: whatsapp online tracker python script 
Python :: split datetime to date and time pandas 
Python :: binary, decimal, hex conversion python 
Python :: np where nan 
Python :: matplotlib dateformatter x axis 
Python :: add one row to dataframe 
Python :: pyqt menubar example 
Python :: convert list to numpy array 
Python :: keras lstm example 
Python :: how to find an element in a list python 
Python :: add a button pyqt5 
Python :: python list all methods of a class 
Python :: pyserial read 
Python :: check if variable is of type decimal.Decimal python 
Python :: while loop python 
Python :: how to make a multiple choice quiz in python with tkinter 
Python :: __new__ python 
Python :: python datetime object 
Python :: python password with special characters 
Python :: ipynb to pdf cide 
Python :: display data from database in django 
Python :: python dict get random key 
Python :: discord get bot profile picture 
Python :: changing the port of django port 
Python :: pandas remove leading trailing spaces in dataframe 
Python :: json decode py 
Python :: if main 
Python :: add column to start of dataframe pandas 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =