From 48729e08fb3f0a67c1f68e64dc64102306959a28 Mon Sep 17 00:00:00 2001 From: NELABALLI BHANUPRAKASH REDDY <123243662+bhanu050604@users.noreply.github.com> Date: Fri, 3 May 2024 23:07:20 +0530 Subject: [PATCH 1/5] Create Task1 --- NELABALLI BHANUPRAKASH REDDY/Task1 | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 NELABALLI BHANUPRAKASH REDDY/Task1 diff --git a/NELABALLI BHANUPRAKASH REDDY/Task1 b/NELABALLI BHANUPRAKASH REDDY/Task1 new file mode 100644 index 0000000..8f8b98b --- /dev/null +++ b/NELABALLI BHANUPRAKASH REDDY/Task1 @@ -0,0 +1,36 @@ +from PIL import Image +import os + +def convert_image(input_path, output_path, output_format): + try: + # Open the image + with Image.open(input_path) as img: + # Convert and save the image to the desired format + img.save(output_path, format=output_format) + print(f"Image converted successfully to {output_format} format.") + except Exception as e: + print(f"An error occurred: {e}") + +def main(): + input_path = input("Enter the path to the input image: ") + output_format = input("Enter the desired output format (e.g., JPEG, PNG, BMP, GIF): ").upper() + + # Validate output format + if output_format not in ['JPEG', 'PNG', 'BMP', 'GIF']: + print("Invalid output format. Please choose from JPEG, PNG, BMP, or GIF.") + return + + # Extract the file name and extension + file_name, file_extension = os.path.splitext(input_path) + + # If the input file already has an extension, remove it + file_name_without_ext = file_name.split('.')[0] + + # Set the output path + output_path = f"{file_name_without_ext}_converted.{output_format.lower()}" + + # Convert the image + convert_image(input_path, output_path, output_format) + +if __name__ == "__main__": + main() From 6d7e6bcac11646ab3ae06eac3dd78a982d3af2ca Mon Sep 17 00:00:00 2001 From: NELABALLI BHANUPRAKASH REDDY <123243662+bhanu050604@users.noreply.github.com> Date: Fri, 3 May 2024 23:09:26 +0530 Subject: [PATCH 2/5] Create Task2 --- NELABALLI BHANUPRAKASH REDDY/Task2 | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 NELABALLI BHANUPRAKASH REDDY/Task2 diff --git a/NELABALLI BHANUPRAKASH REDDY/Task2 b/NELABALLI BHANUPRAKASH REDDY/Task2 new file mode 100644 index 0000000..2fee7c7 --- /dev/null +++ b/NELABALLI BHANUPRAKASH REDDY/Task2 @@ -0,0 +1,43 @@ +import seaborn as sns +import pandas as pd +import matplotlib.pyplot as plt + +# Load the Iris dataset from Seaborn +iris = sns.load_dataset("iris") +numeric_iris = iris.drop(columns='species') + +# Display the first few rows of the dataset +print("First few rows of the dataset:") +print(iris.head()) + +# Summary statistics +print("\nSummary statistics:") +print(iris.describe()) + +# Checking for missing values +print("\nMissing values:") +print(iris.isnull().sum()) + +# Visualizations +# Pairplot +sns.pairplot(iris, hue="species") +plt.title("Pairplot of Iris Dataset") +plt.show() + +# Boxplot +plt.figure(figsize=(10, 6)) +sns.boxplot(data=iris, orient="h") +plt.title("Boxplot of Iris Dataset") +plt.show() + +# Histograms +plt.figure(figsize=(10, 6)) +iris.hist() +plt.suptitle("Histograms of Iris Dataset") +plt.show() + +# Correlation heatmap +plt.figure(figsize=(8, 6)) +sns.heatmap(numeric_iris.corr(), annot=True, cmap="coolwarm") +plt.title("Correlation Heatmap of Iris Dataset") +plt.show() From 53ab18328f5f996521b11dd92f55eda0b6bcb458 Mon Sep 17 00:00:00 2001 From: NELABALLI BHANUPRAKASH REDDY <123243662+bhanu050604@users.noreply.github.com> Date: Fri, 3 May 2024 23:10:48 +0530 Subject: [PATCH 3/5] Create Task3 --- NELABALLI BHANUPRAKASH REDDY/Task3 | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 NELABALLI BHANUPRAKASH REDDY/Task3 diff --git a/NELABALLI BHANUPRAKASH REDDY/Task3 b/NELABALLI BHANUPRAKASH REDDY/Task3 new file mode 100644 index 0000000..5bb8616 --- /dev/null +++ b/NELABALLI BHANUPRAKASH REDDY/Task3 @@ -0,0 +1,45 @@ +import numpy as np +import matplotlib.pyplot as plt +from sklearn.model_selection import train_test_split +from sklearn.linear_model import LinearRegression +from sklearn.metrics import mean_squared_error +import pandas as pd +data_url = "http://lib.stat.cmu.edu/datasets/boston" +raw_df = pd.read_csv(data_url, sep="\s+", skiprows=22, header=None) +data = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]]) +target = raw_df.values[1::2, 2] + +# Load the Boston housing dataset + +X = data +y = target + +# Split the data into training and testing sets +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) + +# Initialize the linear regression model +model = LinearRegression() + +# Fit the model on the training data +model.fit(X_train, y_train) + +# Predict on the training and testing data +y_train_pred = model.predict(X_train) +y_test_pred = model.predict(X_test) + +# Calculate the scores +train_score = model.score(X_train, y_train) +test_score = model.score(X_test, y_test) + +print("Training score:", train_score) +print("Testing score:", test_score) + +# Plot residuals +plt.scatter(y_train_pred, y_train_pred - y_train, c='blue', marker='o', label='Training data') +plt.scatter(y_test_pred, y_test_pred - y_test, c='lightgreen', marker='s', label='Testing data') +plt.xlabel('Predicted values') +plt.ylabel('Residuals') +plt.legend(loc='upper left') +plt.hlines(y=0, xmin=0, xmax=50, lw=2, color='red') +plt.title('Residual plot') +plt.show() From eb5dc5cd9c2d1437a626a28cd4a5f3303de33291 Mon Sep 17 00:00:00 2001 From: NELABALLI BHANUPRAKASH REDDY <123243662+bhanu050604@users.noreply.github.com> Date: Fri, 3 May 2024 23:13:31 +0530 Subject: [PATCH 4/5] Create Task4 Here wp1999881.jpg is an example image of input instead we can use our own inputs. --- NELABALLI BHANUPRAKASH REDDY/Task4 | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 NELABALLI BHANUPRAKASH REDDY/Task4 diff --git a/NELABALLI BHANUPRAKASH REDDY/Task4 b/NELABALLI BHANUPRAKASH REDDY/Task4 new file mode 100644 index 0000000..8f3e332 --- /dev/null +++ b/NELABALLI BHANUPRAKASH REDDY/Task4 @@ -0,0 +1,52 @@ +from PIL import Image +import os + +def get_size_format(b, factor=1024, suffix="B"): + """ + Scale bytes to its proper byte format. + e.g: 1253656 => '1.20MB', 1253656678 => '1.17GB' + """ + for unit in ["", "K", "M", "G", "T", "P", "E", "Z"]: + if b < factor: + return f"{b:.2f}{unit}{suffix}" + b /= factor + return f"{b:.2f}Y{suffix}" + +def compress_img(image_name, new_size_ratio=0.9, quality=90, height="None," to_jpg=True): + # Load the image into memory + img = Image.open(image_name) + + # Print the original image shape + print("[*] Image shape:", img.size) + + # Get the original image size in bytes + image_size = os.path.getsize(image_name) + print("[*] Size before compression:", get_size_format(image_size)) + + if new_size_ratio < 1.0: + # If resizing ratio is below 1.0, multiply width & height with this ratio to reduce image size + img = img.resize((int(img.size[0] * new_size_ratio), int(img.size[1] * new_size_ratio)), Image.ANTIALIAS) + elif width and height: + # If width and height are set, resize with them instead + img = img.resize((width, height), Image.ANTIALIAS) + + # Split the filename and extension + filename, ext = os.path.splitext(image_name) + + # Make a new filename appending "_compressed" to the original file name + if to_jpg: + # Change the extension to JPEG + new_filename = f"{filename}_compressed.jpg" + else: + # Retain the same extension of the original image + new_filename = f"{filename}_compressed{ext}" + + # Save the compressed image + img.save(new_filename, optimize=True, quality=quality) + + # Print the new image shape + print("[+] New Image shape:", img.size) + print(f"[*] Compressed image saved as: {new_filename}") + +# Example usage: +compress_img("wp1999881.jpg", new_size_ratio=0.8, quality=80, From f30388cb43b459a0b998fdbe3aa6b7eb7762aa7e Mon Sep 17 00:00:00 2001 From: NELABALLI BHANUPRAKASH REDDY <123243662+bhanu050604@users.noreply.github.com> Date: Sun, 5 May 2024 14:14:40 +0530 Subject: [PATCH 5/5] Create README.md --- NELABALLI BHANUPRAKASH REDDY/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 NELABALLI BHANUPRAKASH REDDY/README.md diff --git a/NELABALLI BHANUPRAKASH REDDY/README.md b/NELABALLI BHANUPRAKASH REDDY/README.md new file mode 100644 index 0000000..dc62a02 --- /dev/null +++ b/NELABALLI BHANUPRAKASH REDDY/README.md @@ -0,0 +1,20 @@ +Advance Level + +Task 1 :Image Converter: + +Where the program that accepts images in multiple formats that may be in JPEG, PNG, BMP, GIF and converts them into a desired format using Python Imaging Library (PIL) that may be any of the formats mentioned. + + +Task 2:Data Analysis with Pandas: + +In the program on loading the "Iris" dataset from Seaborn and analyzing it using Pandas and performed exploratory data analysis, cleaning, aggregation, visualizations, and correlation calculations. +The output of the program will consits of calculations , graph which will be more understanding to users. + + +Task 3:Linear Regression with Scikit-learn: + +Completed a program by applying linear regression to predict house prices from the Boston housing dataset using scikit-learn and compared train and test scores and plot residuals. + +Task 4:Image Compression: + +Developed a Python program for compressing images while maintaining quality by exploring compression techniques like RLE and DCT and allowing users to adjust compression quality, support various image formats, and provide output options. Optionally, include a user interface.