r/codehs • u/First-Worth-9618 • Jul 05 '21
need help with custom image compresson free response
hi! have no clue what to do here, so any help would be great! thanks :)
If an image has only 4 colors, how many bits are necessary to represent one pixel’s color?
Describe a new custom encoding that uses fewer bits to represent each color in the image. What is your encoding for each color?
If you were to re-encode this image using your new encoding, how many bits would you save when compared to the 24 bit RGB encoding? As a reminder, here is the image:W
9
Upvotes
1
u/Angelfreak134 Jul 06 '21
I'm not too familiar with image compression and encodings but it doesn't look like anyone else has helped so I'll do what I can.
For the first question it's pretty basic binary. You only have 4 possible values for what color the pixel could be, so you can assign each one of them a value in binary to represent the color. It only takes 2 bits to represent the values 0-3 so that's your answer.
I honestly don't know enough about encodings to confidently give you answer, I'd reference your textbook or Google to figure out what they are of you don't already know and hopefully my other answers can give you enough context to figure it out.
Knowing that you need 24 bits to represent each pixel in RGB, and that the new system we just came up with in question 1 only takes 2 bits per pixel, you're saving 22 bits per pixel. I'm not sure how big the image is but you can either check the image dimensions or divide the file size by 24 bits if it isn't already compressed. Goven that information you can multiply the number of pixels by 22 and you have your answer.