{"id":154,"date":"2020-08-18T14:44:10","date_gmt":"2020-08-18T14:44:10","guid":{"rendered":"http:\/\/half4.xyz\/?p=154"},"modified":"2024-02-05T18:51:07","modified_gmt":"2024-02-05T18:51:07","slug":"part-3b-practical-python-imaging-library-pillow","status":"publish","type":"post","link":"https:\/\/half4.xyz\/index.php\/2020\/08\/18\/part-3b-practical-python-imaging-library-pillow\/","title":{"rendered":"Part 3b (Practical): Python Imaging Library (Pillow)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">We now need to write out our sRGB values to an image. We installed Pillow in the introduction, so import that now.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from PIL import Image<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Below our sRGB conversion loop in the Generate() function<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>img = Image.new('RGB', (21,5), color = 'black')\npixels = img.load()\nimg.save('skin_LUT.png')\npixel_index = 0\nfor m in range(7):\n    for x in range(3): # 0 - 32\n        for y in range(5): # 0 - 32\n            xCoord = x + (m * 3)\n            yCoord = y\n            pixels&#91;xCoord, yCoord] = pixelsRGB&#91;pixel_index]\n            pixel_index = pixel_index + 1\nimg.save('skin_LUT.png')\nreturn pixelsRGB<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you now run the code you should get this PNG output \u2013 its small, so I\u2019ve zoomed in:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"238\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-40-1024x238.png\" alt=\"\" class=\"wp-image-309\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-40-1024x238.png 1024w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-40-300x70.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-40-768x179.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-40.png 1435w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">We obviously want more fidelity. We have two options: increase the samples (which is an exponential performance cost), or just use Photoshop to resize it. We\u2019ll do the latter as its much faster, as gives us enough gradation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To do this, we need to select each 1\/3 of the LUT, which is each melanin blend and resize it using a \u201cbicubic smoother\u201d filter to smooth the gradations out, like so:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Select the first 1\/3:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"1024\" height=\"259\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-41-1024x259.png\" alt=\"\" class=\"wp-image-310\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-41-1024x259.png 1024w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-41-300x76.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-41-768x195.png 768w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-41.png 1484w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">2. Copy it to a new image and resize<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"1007\" height=\"619\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-43.png\" alt=\"\" class=\"wp-image-312\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-43.png 1007w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-43-300x184.png 300w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-43-768x472.png 768w\" sizes=\"(max-width: 1007px) 100vw, 1007px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"518\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-44.png\" alt=\"\" class=\"wp-image-313\" srcset=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-44.png 735w, https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-44-300x211.png 300w\" sizes=\"(max-width: 735px) 100vw, 735px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">3. Repeat for the other two LUT sections, then composite them into a new 192*46 pixel image<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"192\" height=\"46\" src=\"https:\/\/half4.xyz\/wp-content\/uploads\/2020\/07\/image-46.png\" alt=\"\" class=\"wp-image-315\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Great! You have got yourself a look-up texture based on physical spectral absorption values!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For reference, here\u2019s the complete project so far:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next we\u2019ll be getting this into Unreal Engine 4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We now need to write out our sRGB values to an image. We installed Pillow in the introduction, so import that now. Below our sRGB conversion loop in the Generate() function If you now run the code you should get this PNG output \u2013 its small, so I\u2019ve zoomed in: We obviously want more fidelity. We have two options: increase the samples (which is an exponential performance cost), or just use Photoshop to resize it. We\u2019ll do the latter as its much faster, as gives us enough gradation. To do this, we need to select each 1\/3 of the LUT, which is each melanin blend and resize it using a \u201cbicubic smoother\u201d filter to smooth the gradations out, like so: 1. Select the first 1\/3: 2. Copy it to a new image and resize 3. Repeat for the other two LUT sections, then composite them into a new 192*46 pixel image Great! You have got yourself a look-up texture based on physical spectral absorption values! For reference, here\u2019s the complete project so far: Next we\u2019ll be getting this into Unreal Engine 4.<\/p>\n","protected":false},"author":1,"featured_media":314,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[8,7],"class_list":["post-154","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-lut","tag-skin"],"_links":{"self":[{"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/posts\/154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=154"}],"version-history":[{"count":8,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/posts\/154\/revisions"}],"predecessor-version":[{"id":1298,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/posts\/154\/revisions\/1298"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/media\/314"}],"wp:attachment":[{"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/half4.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}