Cody

Problem 1368. Create an 8-color version of an image

Solution 2181566

Submitted on 30 Mar 2020 by Takuma Mitamura
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
A = randi([51 255],[600 800 3]); t = [0 25 50]; B = warholer(A,t); assert(all(B(:)==255))

2   Pass
A = randi(100,[800 600 3]); t = [100 255 100]; B = warholer(A,t); assert(all(B(:)==0))

3   Pass
A = zeros(200,200,3); t = randi(255,1,3); B = warholer(A,t); assert(all(B(:)==0))

4   Pass
A = 255*ones(100,100,3); t = randi(254,1,3); B = warholer(A,t); assert(all(B(:)==255))

5   Pass
A(:,:,1) = randi([0 120],[480 320]); A(:,:,2) = randi([80 200],[480 320]); A(:,:,3) = randi([160 240],[480 320]); t = [150 50 150]; B = warholer(A,t); assert(all(all(B(:,:,1)==0))) assert(all(all(B(:,:,2)==255))) assert(all(all(B(:,:,3)==255)))

6   Pass
A(:,:,1) = randi([0 100],[480 320]); A(:,:,2) = randi([80 180],[480 320]); A(:,:,3) = randi([100 240],[480 320]); t = [180 60 250]; B = warholer(A,t); assert(all(all(B(:,:,1)==0))) assert(all(all(B(:,:,2)==255))) assert(all(all(B(:,:,3)==0)))

7   Pass
A(:,:,1) = magic(5)*10; A(:,:,2) = spiral(5)*10; A(:,:,3) = toeplitz(1:5)*50; t = [159 99 149]; B_correct(:,:,1) = [255 255 0 0 0; 255 0 0 0 255; 0 0 0 255 255; 0 0 255 255 0; 0 255 255 0 0]; B_correct(:,:,2) = [255 255 255 255 255; 255 0 0 0 255; 255 0 0 0 255; 255 0 0 0 255; 255 255 255 255 255]; B_correct(:,:,3) = [0 0 255 255 255; 0 0 0 255 255; 255 0 0 0 255; 255 255 0 0 0; 255 255 255 0 0]; assert(isequal(warholer(A,t),B_correct))

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!