{"id":100,"date":"2021-03-31T02:28:57","date_gmt":"2021-03-31T02:28:57","guid":{"rendered":"http:\/\/learnlearn.uk\/algorithms\/?page_id=100"},"modified":"2021-05-10T23:56:10","modified_gmt":"2021-05-10T23:56:10","slug":"compression-algorithms","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/algorithms\/compression-algorithms\/","title":{"rendered":"Compression Algorithms"},"content":{"rendered":"<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Introduction<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Why do we need compression?<\/h3>\n<p>Today&#8217;s modern smartphones have huge amount of storage, so why do we need compression? Let&#8217;s find out.<\/p>\n<p><strong>Question 1a<\/strong><\/p>\n<p>An iPhone camera has a resolution of 12 Megapixels and each pixel requires 3 bytes to store the image. How big would would an uncompressed image be?<\/p>\n<p><em>Hint: Mega = million<\/em><\/p>\n<div class=\"arconix-toggle-wrap\"><div class=\"arconix-toggle-title toggle-closed\"><i class='fa fa-plus-square'><\/i>Answer<\/div><div class=\"arconix-toggle-content\">\n<p>12,000,000 x 3 = <span style=\"text-decoration: underline;\">36,000,000 Bytes<\/span><\/p>\n<\/div><\/div>\n<p><strong>Question 1b<\/strong><\/p>\n<p>If an iPhone has a storage capacity of 32 Gigabytes, how many images could you store on it before you ran out of space?<\/p>\n<p>Hint: Giga = Billion<\/p>\n<div class=\"arconix-toggle-wrap\"><div class=\"arconix-toggle-title toggle-closed\"><i class='fa fa-plus-square'><\/i><\/div><div class=\"arconix-toggle-content\">\n<p>32,000,000,000 \/ 36,000,000 = <span style=\"text-decoration: underline;\">888 photos<\/span><\/p>\n<\/div><\/div>\n<p>That means that without compression you would run out of space before you even took a thousand selfies&#8230;.<\/p>\n<p><strong>Question 1c<\/strong><\/p>\n<p>Now image recording videos &#8211; A normal video would record 24 frames per second. Assuming your iPhone recorded at 4K resolution (3840&#215;2160 pixels). How long could you record for before running out of space?<\/p>\n<div class=\"arconix-toggle-wrap\"><div class=\"arconix-toggle-title toggle-closed\"><i class='fa fa-plus-square'><\/i><\/div><div class=\"arconix-toggle-content\">\n<p>3840 x 2160 =\u00a0 \u00a0 8,294,400 (Calculate the total number of pixels)<\/p>\n<p>8,294,400 x 3 = 24,883,200 Bytes per frame (Calculate the total number of bytes)<\/p>\n<p>24,883,200 x 24\u00a0 =\u00a0597,196,800 Bytes per second (multiply by 24 to get how many bytes per second)<\/p>\n<p>32,000,000,000 \/ 597,196,800 =\u00a0<span style=\"text-decoration: underline;\">53.5 seconds!<\/span><\/p>\n<p>And we haven&#8217;t even including recording the sound&#8230;<\/p>\n<\/div><\/div>\n<p>As you can see without compression your phone wouldn&#8217;t be very useful.<\/p>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">Run Length Encoding<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Run Length Encoding (RLE) compression<\/h3>\n<div id=\"attachment_171\" style=\"width: 352px\" class=\"wp-caption alignright\"><img aria-describedby=\"caption-attachment-171\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-171\" src=\"https:\/\/learnlearn.uk\/algorithms\/wp-content\/uploads\/sites\/12\/2021\/03\/smileys.png\" alt=\"\" width=\"342\" height=\"738\" srcset=\"https:\/\/learnlearn.uk\/algorithms\/wp-content\/uploads\/sites\/12\/2021\/03\/smileys.png 342w, https:\/\/learnlearn.uk\/algorithms\/wp-content\/uploads\/sites\/12\/2021\/03\/smileys-139x300.png 139w\" sizes=\"(max-width: 342px) 100vw, 342px\" \/><p id=\"caption-attachment-171\" class=\"wp-caption-text\">Placing a grid overlay over a B&amp;W image<\/p><\/div>\n<p>Run length encoding works by identifying runs of identical data and recording the data, together with the number of pixels that it represents.<\/p>\n<p>Take a look at the black and white sad image.<\/p>\n<p>If we were to store this image matrix as text it would be (starting from the top-left and working line by line)<\/p>\n<p><strong>Uncompressed<\/strong><\/p>\n<p><span style=\"color: #0000ff;\">wwwwwwwwwbbwwbbwwbbwwbbwwwwwwwwwwwwwwwwwwbbbbbbwwbwwwwbwwwwwwwww<\/span><\/p>\n<p>We can compress this image by writing the length of the run of data followed by the data itself.<\/p>\n<p><strong>Compressed<\/strong><\/p>\n<p><span style=\"color: #0000ff;\">9w2b2w2b2w2b2w2b18w6b2w1b4w1b9w<\/span><\/p>\n<p>Here you can see that we have compressed the data by over 50% without losing any of the data.\u00a0This form of compression was widely used to compression data when sending data via a fax machine, as all faxes are black and white.<\/p>\n<p>If we wanted to we could <strong>reconstruct the original data<\/strong> using the compressed run length data. Compression where you can reconstruct the original data from the compressed data is known as<strong> lossless<\/strong> compression.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">Activity<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Activity<\/h3>\n<p>Have a go at creating a smiley face in the grid bow below!<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/trinket.io\/embed\/html\/bda51f24c8?outputOnly=true&amp;start=result\" width=\"100%\" height=\"450\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>Can you right down a compressed version of the image that you created using run length encoding?<\/p>\n\n<\/div><h2 class=\"tabtitle\">Learning Log<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Learning Log<\/h3>\n<p>You should now complete your learning log for today&#8217;s lesson.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Extension task<\/strong><\/p>\n<ul>\n<li>LZ compression<\/li>\n<li>Huffman encoding<\/li>\n<\/ul>\n\n<\/div><h2 class=\"tabtitle\">Resources<\/h2>\n<div class=\"tabcontent\">\n\n<p><a href=\"https:\/\/youtu.be\/JsTptu56GM8\">Extension Activity &#8211; Huffman Encoding Video<\/a><\/p>\n<p><a href=\"https:\/\/www.tes.com\/teaching-resource\/huffman-encoding-worksheet-11988134\">Huffman Tree Worksheet<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/div><\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Why do we need compression? Today&#8217;s modern smartphones have huge amount of storage, so why do we need compression? Let&#8217;s find out. Question 1a An iPhone camera has a resolution of 12 Megapixels and each pixel requires 3 bytes to store the image. How big would would an uncompressed image be? Hint: Mega = million&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/algorithms\/compression-algorithms\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Compression Algorithms<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":70,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Compression Algorithms - Algorithms<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/learnlearn.uk\/algorithms\/compression-algorithms\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Compression Algorithms - Algorithms\" \/>\n<meta property=\"og:description\" content=\"Why do we need compression? Today&#8217;s modern smartphones have huge amount of storage, so why do we need compression? Let&#8217;s find out. Question 1a An iPhone camera has a resolution of 12 Megapixels and each pixel requires 3 bytes to store the image. How big would would an uncompressed image be? Hint: Mega = million&hellip;&nbsp;Read More &raquo;Compression Algorithms\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/algorithms\/compression-algorithms\/\" \/>\n<meta property=\"og:site_name\" content=\"Algorithms\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-10T23:56:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/learnlearn.uk\/algorithms\/wp-content\/uploads\/sites\/12\/2021\/03\/smileys.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnlearn.uk\/algorithms\/compression-algorithms\/\",\"url\":\"https:\/\/learnlearn.uk\/algorithms\/compression-algorithms\/\",\"name\":\"Compression Algorithms - Algorithms\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/algorithms\/#website\"},\"datePublished\":\"2021-03-31T02:28:57+00:00\",\"dateModified\":\"2021-05-10T23:56:10+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/algorithms\/compression-algorithms\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/algorithms\/compression-algorithms\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/algorithms\/compression-algorithms\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"KS3 Algorithms Unit\",\"item\":\"https:\/\/learnlearn.uk\/algorithms\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Compression Algorithms\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/algorithms\/#website\",\"url\":\"https:\/\/learnlearn.uk\/algorithms\/\",\"name\":\"Algorithms\",\"description\":\"An intro\",\"publisher\":{\"@id\":\"https:\/\/learnlearn.uk\/algorithms\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/algorithms\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/learnlearn.uk\/algorithms\/#organization\",\"name\":\"Algorithms\",\"url\":\"https:\/\/learnlearn.uk\/algorithms\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/learnlearn.uk\/algorithms\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/learnlearn.uk\/algorithms\/wp-content\/uploads\/sites\/12\/2021\/04\/LearnLearnLogowhite.png\",\"contentUrl\":\"https:\/\/learnlearn.uk\/algorithms\/wp-content\/uploads\/sites\/12\/2021\/04\/LearnLearnLogowhite.png\",\"width\":710,\"height\":98,\"caption\":\"Algorithms\"},\"image\":{\"@id\":\"https:\/\/learnlearn.uk\/algorithms\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Compression Algorithms - Algorithms","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/learnlearn.uk\/algorithms\/compression-algorithms\/","og_locale":"en_GB","og_type":"article","og_title":"Compression Algorithms - Algorithms","og_description":"Why do we need compression? Today&#8217;s modern smartphones have huge amount of storage, so why do we need compression? Let&#8217;s find out. Question 1a An iPhone camera has a resolution of 12 Megapixels and each pixel requires 3 bytes to store the image. How big would would an uncompressed image be? Hint: Mega = million&hellip;&nbsp;Read More &raquo;Compression Algorithms","og_url":"https:\/\/learnlearn.uk\/algorithms\/compression-algorithms\/","og_site_name":"Algorithms","article_modified_time":"2021-05-10T23:56:10+00:00","og_image":[{"url":"https:\/\/learnlearn.uk\/algorithms\/wp-content\/uploads\/sites\/12\/2021\/03\/smileys.png"}],"twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/algorithms\/compression-algorithms\/","url":"https:\/\/learnlearn.uk\/algorithms\/compression-algorithms\/","name":"Compression Algorithms - Algorithms","isPartOf":{"@id":"https:\/\/learnlearn.uk\/algorithms\/#website"},"datePublished":"2021-03-31T02:28:57+00:00","dateModified":"2021-05-10T23:56:10+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/algorithms\/compression-algorithms\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/algorithms\/compression-algorithms\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/algorithms\/compression-algorithms\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"KS3 Algorithms Unit","item":"https:\/\/learnlearn.uk\/algorithms\/"},{"@type":"ListItem","position":2,"name":"Compression Algorithms"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/algorithms\/#website","url":"https:\/\/learnlearn.uk\/algorithms\/","name":"Algorithms","description":"An intro","publisher":{"@id":"https:\/\/learnlearn.uk\/algorithms\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/algorithms\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/learnlearn.uk\/algorithms\/#organization","name":"Algorithms","url":"https:\/\/learnlearn.uk\/algorithms\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/learnlearn.uk\/algorithms\/#\/schema\/logo\/image\/","url":"https:\/\/learnlearn.uk\/algorithms\/wp-content\/uploads\/sites\/12\/2021\/04\/LearnLearnLogowhite.png","contentUrl":"https:\/\/learnlearn.uk\/algorithms\/wp-content\/uploads\/sites\/12\/2021\/04\/LearnLearnLogowhite.png","width":710,"height":98,"caption":"Algorithms"},"image":{"@id":"https:\/\/learnlearn.uk\/algorithms\/#\/schema\/logo\/image\/"}}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/algorithms\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":null,"rttpg_excerpt":"Why do we need compression? Today&#8217;s modern smartphones have huge amount of storage, so why do we need compression? Let&#8217;s find out. Question 1a An iPhone camera has a resolution of 12 Megapixels and each pixel requires 3 bytes to store the image. How big would would an uncompressed image be? Hint: Mega = million&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/algorithms\/wp-json\/wp\/v2\/pages\/100"}],"collection":[{"href":"https:\/\/learnlearn.uk\/algorithms\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnlearn.uk\/algorithms\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/algorithms\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/algorithms\/wp-json\/wp\/v2\/comments?post=100"}],"version-history":[{"count":22,"href":"https:\/\/learnlearn.uk\/algorithms\/wp-json\/wp\/v2\/pages\/100\/revisions"}],"predecessor-version":[{"id":186,"href":"https:\/\/learnlearn.uk\/algorithms\/wp-json\/wp\/v2\/pages\/100\/revisions\/186"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/algorithms\/wp-json\/wp\/v2\/media?parent=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}