{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-04-06T14:01:22.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2026-04-06T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":46028,"title":"Paint it black!","description":"\u003chttps://en.wikipedia.org/wiki/Flood_fill Flood fill\u003e is the algorithm used by bucket-fill tools in many image editors. The idea is that all connected pixels with the input color should have it changed to an output color starting at a pixel P = (x,y). Your task is to implement this algorithm replacing all colors within some tolerance (distance) from the input color with black. \r\n\r\nFor instance:\r\n\r\nif the input_color=9, tolerance = 0, and P=[1,1], then the following grayscale image,\r\n\r\n  9 9 9 2 9\r\n  9 9 9 2 9\r\n  2 2 2 9 9 \r\n  9 9 9 9 9\r\n\r\nbecomes,\r\n\r\n  0 0 0 2 9\r\n  0 0 0 2 9\r\n  2 2 2 9 9 \r\n  9 9 9 9 9\r\n\r\nAssume that all pixels have \u003chttps://en.wikipedia.org/wiki/Pixel_connectivity#4-connected 4-neighborhoods\u003e. And use the \u003chttps://en.wikipedia.org/wiki/Taxicab_geometry Manhattan distance\u003e to decide if a color, a 1xn vector, is within tolerance. ","description_html":"\u003cp\u003e\u003ca href = \"https://en.wikipedia.org/wiki/Flood_fill\"\u003eFlood fill\u003c/a\u003e is the algorithm used by bucket-fill tools in many image editors. The idea is that all connected pixels with the input color should have it changed to an output color starting at a pixel P = (x,y). Your task is to implement this algorithm replacing all colors within some tolerance (distance) from the input color with black.\u003c/p\u003e\u003cp\u003eFor instance:\u003c/p\u003e\u003cp\u003eif the input_color=9, tolerance = 0, and P=[1,1], then the following grayscale image,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e9 9 9 2 9\r\n9 9 9 2 9\r\n2 2 2 9 9 \r\n9 9 9 9 9\r\n\u003c/pre\u003e\u003cp\u003ebecomes,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e0 0 0 2 9\r\n0 0 0 2 9\r\n2 2 2 9 9 \r\n9 9 9 9 9\r\n\u003c/pre\u003e\u003cp\u003eAssume that all pixels have \u003ca href = \"https://en.wikipedia.org/wiki/Pixel_connectivity#4-connected\"\u003e4-neighborhoods\u003c/a\u003e. And use the \u003ca href = \"https://en.wikipedia.org/wiki/Taxicab_geometry\"\u003eManhattan distance\u003c/a\u003e to decide if a color, a 1xn vector, is within tolerance.\u003c/p\u003e","function_template":"function J = floodfill(I, p, input_color, tolerance)\r\n  J = I;\r\nend","test_suite":"%%\r\nfiletext = fileread('floodfill.m');\r\nassert(isempty(strfind(filetext, 'eval')),       'Eval forbidden.');\r\nassert(isempty(strfind(filetext, 'regexp')),     'Regexp forbidden.');\r\nassert(isempty(strfind(filetext, '!')),          'Shell commands are forbidden.');\r\nassert(isempty(strfind(filetext, 'mlock')),      'mlock is forbidden.');\r\nassert(isempty(strfind(filetext, 'munlock')),    'munlock is forbidden.');\r\n%%\r\np = [1, 1];\r\ninput_color = 9;\r\ntolerance = 0;\r\nI =[9     9     9     2     9;\r\n    9     9     9     2     9;\r\n    2     2     2     9     9;\r\n    9     9     9     9     9];\r\ny_correct = [105\t177\t73\t204\t122\t130\t214\t108\t173\t122\t154\t247\t132\t149\t158\t137\t49\t171\t159\t188\t197\t146\t104\t212\t84\t234\t120\t67\t160\t122\t71\t32\t47\t185\t5\t209\t49\t198\t215\t117\t128\t125\t185\t181\t102\t14\t159\t250\t201\t95\t158\t167\t242\t21\t94\t99\t214\t253\t223\t168\t146\t133\t126\t232];\r\nJ = floodfill(I, p, input_color, tolerance);\r\nassert(all(uint8(py.hashlib.sha512(mat2str(J)).digest()) == y_correct));\r\n\r\n%%\r\np = [115, 133];\r\ninput_color = 1;\r\ntolerance = 0;\r\nI=imread(fullfile(matlabroot,'toolbox','images','imdata','blobs.png'));\r\ny_correct = [135\t217\t59\t179\t157\t208\t161\t95\t218\t159\t210\t244\t62\t237\t115\t179\t200\t252\t175\t39\t230\t197\t55\t36\t8\t79\t77\t168\t253\t109\t230\t204\t158\t114\t20\t231\t91\t63\t169\t114\t57\t73\t121\t96\t51\t204\t92\t136\t34\t220\t205\t158\t222\t148\t80\t205\t117\t32\t220\t80\t220\t62\t195\t26];\r\nJ = floodfill(I, p, input_color, tolerance);\r\nassert(all(uint8(py.hashlib.sha512(mat2str(J)).digest()) == y_correct));\r\n\r\n%%\r\np = [170, 70];\r\ninput_color = 1;\r\ntolerance = 0;\r\nI=imread(fullfile(matlabroot,'toolbox','images','imdata','blobs.png'));\r\ny_correct = [45\t21\t215\t148\t24\t198\t184\t203\t33\t38\t222\t107\t60\t205\t211\t33\t76\t33\t62\t139\t133\t58\t42\t238\t77\t128\t243\t214\t143\t201\t181\t109\t218\t80\t3\t41\t44\t130\t179\t21\t51\t87\t168\t161\t118\t110\t241\t214\t236\t45\t210\t130\t28\t94\t170\t39\t9\t240\t10\t103\t158\t207\t214\t203];\r\nJ = floodfill(I, p, input_color, tolerance);\r\nassert(all(uint8(py.hashlib.sha512(mat2str(J)).digest()) == y_correct));\r\n\r\n%%\r\np = [1500, 1840];\r\ninput_color = 204;\r\ntolerance = 5;\r\nI=imread(fullfile(matlabroot,'toolbox','images','imdata','concordorthophoto.png'));\r\ny_correct = [180\t96\t232\t179\t100\t190\t0\t55\t194\t91\t49\t45\t220\t214\t233\t3\t164\t217\t254\t197\t27\t26\t207\t107\t116\t80\t153\t76\t121\t137\t231\t21\t236\t37\t200\t112\t254\t5\t121\t70\t181\t182\t106\t13\t39\t235\t188\t82\t140\t107\t118\t11\t163\t102\t78\t97\t230\t36\t252\t46\t165\t126\t85\t17];\r\nJ = floodfill(I, p, input_color, tolerance);\r\nassert(all(uint8(py.hashlib.sha512(mat2str(J)).digest()) == y_correct));\r\n\r\n%%\r\np = [375, 635];\r\ninput_color = [202, 67, 37];\r\ntolerance = 175;\r\nI=imread(fullfile(matlabroot,'toolbox','images','imdata','flamingos.jpg'));\r\ny_correct = [30\t139\t106\t7\t97\t110\t190\t130\t24\t218\t242\t177\t34\t121\t66\t214\t96\t87\t10\t195\t170\t9\t145\t230\t222\t27\t243\t72\t82\t124\t63\t198\t151\t209\t215\t250\t32\t44\t207\t179\t112\t121\t173\t232\t193\t144\t31\t238\t152\t205\t145\t57\t41\t194\t8\t221\t119\t157\t210\t6\t83\t112\t142\t99];\r\nJ = floodfill(I, p, input_color, tolerance);\r\nassert(all(uint8(py.hashlib.sha512(mat2str(J(:))).digest()) == y_correct));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":5,"created_by":443343,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":2,"test_suite_updated_at":"2020-07-19T21:02:55.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-07-05T03:08:28.000Z","updated_at":"2024-10-30T23:17:50.000Z","published_at":"2020-07-19T20:59:48.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Flood_fill\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFlood fill\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is the algorithm used by bucket-fill tools in many image editors. The idea is that all connected pixels with the input color should have it changed to an output color starting at a pixel P = (x,y). Your task is to implement this algorithm replacing all colors within some tolerance (distance) from the input color with black.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor instance:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eif the input_color=9, tolerance = 0, and P=[1,1], then the following grayscale image,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[9 9 9 2 9\\n9 9 9 2 9\\n2 2 2 9 9 \\n9 9 9 9 9]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ebecomes,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[0 0 0 2 9\\n0 0 0 2 9\\n2 2 2 9 9 \\n9 9 9 9 9]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssume that all pixels have\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Pixel_connectivity#4-connected\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e4-neighborhoods\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. And use the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Taxicab_geometry\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eManhattan distance\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e to decide if a color, a 1xn vector, is within tolerance.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":46028,"title":"Paint it black!","description":"\u003chttps://en.wikipedia.org/wiki/Flood_fill Flood fill\u003e is the algorithm used by bucket-fill tools in many image editors. The idea is that all connected pixels with the input color should have it changed to an output color starting at a pixel P = (x,y). Your task is to implement this algorithm replacing all colors within some tolerance (distance) from the input color with black. \r\n\r\nFor instance:\r\n\r\nif the input_color=9, tolerance = 0, and P=[1,1], then the following grayscale image,\r\n\r\n  9 9 9 2 9\r\n  9 9 9 2 9\r\n  2 2 2 9 9 \r\n  9 9 9 9 9\r\n\r\nbecomes,\r\n\r\n  0 0 0 2 9\r\n  0 0 0 2 9\r\n  2 2 2 9 9 \r\n  9 9 9 9 9\r\n\r\nAssume that all pixels have \u003chttps://en.wikipedia.org/wiki/Pixel_connectivity#4-connected 4-neighborhoods\u003e. And use the \u003chttps://en.wikipedia.org/wiki/Taxicab_geometry Manhattan distance\u003e to decide if a color, a 1xn vector, is within tolerance. ","description_html":"\u003cp\u003e\u003ca href = \"https://en.wikipedia.org/wiki/Flood_fill\"\u003eFlood fill\u003c/a\u003e is the algorithm used by bucket-fill tools in many image editors. The idea is that all connected pixels with the input color should have it changed to an output color starting at a pixel P = (x,y). Your task is to implement this algorithm replacing all colors within some tolerance (distance) from the input color with black.\u003c/p\u003e\u003cp\u003eFor instance:\u003c/p\u003e\u003cp\u003eif the input_color=9, tolerance = 0, and P=[1,1], then the following grayscale image,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e9 9 9 2 9\r\n9 9 9 2 9\r\n2 2 2 9 9 \r\n9 9 9 9 9\r\n\u003c/pre\u003e\u003cp\u003ebecomes,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e0 0 0 2 9\r\n0 0 0 2 9\r\n2 2 2 9 9 \r\n9 9 9 9 9\r\n\u003c/pre\u003e\u003cp\u003eAssume that all pixels have \u003ca href = \"https://en.wikipedia.org/wiki/Pixel_connectivity#4-connected\"\u003e4-neighborhoods\u003c/a\u003e. And use the \u003ca href = \"https://en.wikipedia.org/wiki/Taxicab_geometry\"\u003eManhattan distance\u003c/a\u003e to decide if a color, a 1xn vector, is within tolerance.\u003c/p\u003e","function_template":"function J = floodfill(I, p, input_color, tolerance)\r\n  J = I;\r\nend","test_suite":"%%\r\nfiletext = fileread('floodfill.m');\r\nassert(isempty(strfind(filetext, 'eval')),       'Eval forbidden.');\r\nassert(isempty(strfind(filetext, 'regexp')),     'Regexp forbidden.');\r\nassert(isempty(strfind(filetext, '!')),          'Shell commands are forbidden.');\r\nassert(isempty(strfind(filetext, 'mlock')),      'mlock is forbidden.');\r\nassert(isempty(strfind(filetext, 'munlock')),    'munlock is forbidden.');\r\n%%\r\np = [1, 1];\r\ninput_color = 9;\r\ntolerance = 0;\r\nI =[9     9     9     2     9;\r\n    9     9     9     2     9;\r\n    2     2     2     9     9;\r\n    9     9     9     9     9];\r\ny_correct = [105\t177\t73\t204\t122\t130\t214\t108\t173\t122\t154\t247\t132\t149\t158\t137\t49\t171\t159\t188\t197\t146\t104\t212\t84\t234\t120\t67\t160\t122\t71\t32\t47\t185\t5\t209\t49\t198\t215\t117\t128\t125\t185\t181\t102\t14\t159\t250\t201\t95\t158\t167\t242\t21\t94\t99\t214\t253\t223\t168\t146\t133\t126\t232];\r\nJ = floodfill(I, p, input_color, tolerance);\r\nassert(all(uint8(py.hashlib.sha512(mat2str(J)).digest()) == y_correct));\r\n\r\n%%\r\np = [115, 133];\r\ninput_color = 1;\r\ntolerance = 0;\r\nI=imread(fullfile(matlabroot,'toolbox','images','imdata','blobs.png'));\r\ny_correct = [135\t217\t59\t179\t157\t208\t161\t95\t218\t159\t210\t244\t62\t237\t115\t179\t200\t252\t175\t39\t230\t197\t55\t36\t8\t79\t77\t168\t253\t109\t230\t204\t158\t114\t20\t231\t91\t63\t169\t114\t57\t73\t121\t96\t51\t204\t92\t136\t34\t220\t205\t158\t222\t148\t80\t205\t117\t32\t220\t80\t220\t62\t195\t26];\r\nJ = floodfill(I, p, input_color, tolerance);\r\nassert(all(uint8(py.hashlib.sha512(mat2str(J)).digest()) == y_correct));\r\n\r\n%%\r\np = [170, 70];\r\ninput_color = 1;\r\ntolerance = 0;\r\nI=imread(fullfile(matlabroot,'toolbox','images','imdata','blobs.png'));\r\ny_correct = [45\t21\t215\t148\t24\t198\t184\t203\t33\t38\t222\t107\t60\t205\t211\t33\t76\t33\t62\t139\t133\t58\t42\t238\t77\t128\t243\t214\t143\t201\t181\t109\t218\t80\t3\t41\t44\t130\t179\t21\t51\t87\t168\t161\t118\t110\t241\t214\t236\t45\t210\t130\t28\t94\t170\t39\t9\t240\t10\t103\t158\t207\t214\t203];\r\nJ = floodfill(I, p, input_color, tolerance);\r\nassert(all(uint8(py.hashlib.sha512(mat2str(J)).digest()) == y_correct));\r\n\r\n%%\r\np = [1500, 1840];\r\ninput_color = 204;\r\ntolerance = 5;\r\nI=imread(fullfile(matlabroot,'toolbox','images','imdata','concordorthophoto.png'));\r\ny_correct = [180\t96\t232\t179\t100\t190\t0\t55\t194\t91\t49\t45\t220\t214\t233\t3\t164\t217\t254\t197\t27\t26\t207\t107\t116\t80\t153\t76\t121\t137\t231\t21\t236\t37\t200\t112\t254\t5\t121\t70\t181\t182\t106\t13\t39\t235\t188\t82\t140\t107\t118\t11\t163\t102\t78\t97\t230\t36\t252\t46\t165\t126\t85\t17];\r\nJ = floodfill(I, p, input_color, tolerance);\r\nassert(all(uint8(py.hashlib.sha512(mat2str(J)).digest()) == y_correct));\r\n\r\n%%\r\np = [375, 635];\r\ninput_color = [202, 67, 37];\r\ntolerance = 175;\r\nI=imread(fullfile(matlabroot,'toolbox','images','imdata','flamingos.jpg'));\r\ny_correct = [30\t139\t106\t7\t97\t110\t190\t130\t24\t218\t242\t177\t34\t121\t66\t214\t96\t87\t10\t195\t170\t9\t145\t230\t222\t27\t243\t72\t82\t124\t63\t198\t151\t209\t215\t250\t32\t44\t207\t179\t112\t121\t173\t232\t193\t144\t31\t238\t152\t205\t145\t57\t41\t194\t8\t221\t119\t157\t210\t6\t83\t112\t142\t99];\r\nJ = floodfill(I, p, input_color, tolerance);\r\nassert(all(uint8(py.hashlib.sha512(mat2str(J(:))).digest()) == y_correct));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":5,"created_by":443343,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":2,"test_suite_updated_at":"2020-07-19T21:02:55.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-07-05T03:08:28.000Z","updated_at":"2024-10-30T23:17:50.000Z","published_at":"2020-07-19T20:59:48.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Flood_fill\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFlood fill\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is the algorithm used by bucket-fill tools in many image editors. The idea is that all connected pixels with the input color should have it changed to an output color starting at a pixel P = (x,y). Your task is to implement this algorithm replacing all colors within some tolerance (distance) from the input color with black.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor instance:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eif the input_color=9, tolerance = 0, and P=[1,1], then the following grayscale image,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[9 9 9 2 9\\n9 9 9 2 9\\n2 2 2 9 9 \\n9 9 9 9 9]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ebecomes,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[0 0 0 2 9\\n0 0 0 2 9\\n2 2 2 9 9 \\n9 9 9 9 9]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssume that all pixels have\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Pixel_connectivity#4-connected\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e4-neighborhoods\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. And use the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://en.wikipedia.org/wiki/Taxicab_geometry\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eManhattan distance\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e to decide if a color, a 1xn vector, is within tolerance.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"tag:\"bucket-fill\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"bucket-fill\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"bucket-fill\"","","\"","bucket-fill","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fdd472a6878\u003e":null,"#\u003cMathWorks::Search::Field:0x00007fdd472a67d8\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fdd472a5f18\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fdd472a6af8\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fdd472a6a58\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fdd472a69b8\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fdd472a6918\u003e":"tag:\"bucket-fill\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fdd472a6918\u003e":"tag:\"bucket-fill\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"cody-search","password":"78X075ddcV44","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"bucket-fill\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"bucket-fill\"","","\"","bucket-fill","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fdd472a6878\u003e":null,"#\u003cMathWorks::Search::Field:0x00007fdd472a67d8\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fdd472a5f18\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fdd472a6af8\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fdd472a6a58\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fdd472a69b8\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fdd472a6918\u003e":"tag:\"bucket-fill\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fdd472a6918\u003e":"tag:\"bucket-fill\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":46028,"difficulty_rating":"hard"}]}}