Skip to content

Instantly share code, notes, and snippets.

View Kh4lil's full-sized avatar
๐ŸŽ—๏ธ

Khalil O. Kh4lil

๐ŸŽ—๏ธ
  • United States
View GitHub Profile
@Kh4lil
Kh4lil / grayscale_luminosity_kernel.cu
Last active February 27, 2021 01:23
__global__ void grayscale_luminosity_kernel
/**
* @brief Luminosity Kernel
* Converts colored image to grayscale using Luminosity algorithm
*/
__global__ void grayscale_luminosity_kernel(unsigned char* input, unsigned char* output, int width, int height, int colored_WidthStep, int grayscaled_WidthStep) {
const int xIndex = blockIdx.x * blockDim.x + threadIdx.x; // x index of current thread.
const int yIndex = blockIdx.y * blockDim.y + threadIdx.y; // y index of current thread.
if ((xIndex < width) && (yIndex < height))
@Kh4lil
Kh4lil / grayscale_average_kernel.cu
Last active February 27, 2021 01:23
__global__ void grayscale_average_kernel
/**
* @brief Average Kernel
* Converts colored image to grayscale using Average algorithm
*/
__global__ void grayscale_average_kernel(unsigned char* input, unsigned char* output, int width, int height, int colored_WidthStep, int grayscaled_WidthStep) {
const int xIndex = blockIdx.x * blockDim.x + threadIdx.x; // x index of current thread.
const int yIndex = blockIdx.y * blockDim.y + threadIdx.y; // y index of current thread.
if ((xIndex < width) && (yIndex < height))
@Kh4lil
Kh4lil / grayscale_lightness_kernel.cu
Last active February 27, 2021 01:22
void grayscale_lightness_kernel
/**
* @brief Lightness Kernel
* Converts colored image to grayscale using Lightness algorithm
*/
__global__ void grayscale_lightness_kernel(unsigned char* input, unsigned char* output, int width, int height, int colored_WidthStep, int grayscaled_WidthStep) {
const int xIndex = blockIdx.x * blockDim.x + threadIdx.x; // x index of current thread.
const int yIndex = blockIdx.y * blockDim.y + threadIdx.y; // y index of current thread.
if ((xIndex < width) && (yIndex < height))
@Kh4lil
Kh4lil / convert_color_to_grayscaleFunction.cu
Last active February 27, 2021 01:22
Wrapper function for cuda grayscale image
/*
* Wrapper function
* @param input The input image.
* @param input The output image to be modified.
*/
void convert_color_to_grayscale(const cv::Mat& inputImage, cv::Mat& outputImage) {
const int inputImage_ColoredBytes = inputImage.step * inputImage.rows; // Calculate total number of bytes of input image.
const int outputImage_GrayBytes = outputImage.step * outputImage.rows; // Calculate total number of bytes of output image.
@Kh4lil
Kh4lil / ImageGrayscale.cu
Last active February 27, 2021 01:41
ImageGrayscale.cu
int main() {
std::string inputImage = "model.ppm"; // Import image
cv::Mat originalImage = cv::imread(inputImage);
cv::Mat imageResizeDoubled;
cv::Mat imageResizeQuadrupeled;
std::cout << "Original image size: " << originalImage.size() << std::endl; // Display resolution of original image.
// Image resizing:
float scale = 2; // scale factor. To be changed from 2 to 4 if needed.
# Importing the dataset
from sklearn.datasets import load_iris
irisDataSet = load_iris()
X = irisDataSet.data
y = irisDataSet.target
# Split the data set into training and testing
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(irisDataSet['data'], irisDataSet['target'], random_state=0)
# New iris with below information
X_newIris = np.array([[5.0, 2.9, 1.0, 0.2]])
predictNew = KNN_Classifier.predict(X_new)
print(predictNew)
# >>>Output: [0]
# Split the data set into training and testing
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(iris['data'], iris['target'], random_state=0)
from sklearn.neighbors import KNeighborsClassifier
KNN_Classifier = KNeighborsClassifier(n_neighbors=1)
KNN_Classifier.fit(X_train, y_train)
# Importing the dataset
from sklearn.datasets import load_iris
irisDataSet = load_iris()
X = irisDataSet.data
y = irisDataSet.target
# Plotting
import matplotlib.pyplot as plt
#
features = irisDataSet.data.T
public bool compareTrees(TreeNode p, TreeNode q) {
//Check for baseCase:
if (p == null && q == null){
return true;
}if (p == null || q == null){
return false;
//Compare the values of the two nodes:
}if (p.val != q.val){
return false;
}