Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

ImageCompresion

A project for compresing images using SVD algorithm. The script splits the image into its red, green, and blue color channels, applies SVD to each channel, and then reconstructs the image with reduced dimensions. This compression technique can significantly reduce the size of the image while preserving its visual quality.

Tabel of content

Requirements

This project uses Numpy and PIL libraries.

Code Explanation

The compress_color_image function performs the following steps:

1. Load Images:

image = Image.open(image_path)
A = np.array(image)

2. Split color channels

R = A[:,:,0]
G = A[:,:,1]
B = A[:,:,2]

3. Compress each channel using SVG

def compress_channel(channel):
    U, sigma, VT = np.linalg.svd(channel, full_matrices=False)
    U_k = U[:, :k]
    sigma_k = np.diag(sigma[:k])
    VT_k = VT[:k, :]
    return np.dot(U_k, np.dot(sigma_k, VT_k))

R_k = compress_channel(R)
G_k = compress_channel(G)
B_k = compress_channel(B)

4. Reconstruct and Save the image

compressed_image_array = np.stack([R_k, G_k, B_k], axis=2)
compressed_image_array = np.clip(compressed_image_array, 0, 255)
compressed_image = Image.fromarray(compressed_image_array.astype('uint8'))
compressed_image.save(output_path)

Usage

  1. Save the code file and move it to the image folder
  2. Rename the last code line
  3. Run the code

About

No description or website provided.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages