This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
NewerOlder