Cody

Problem 818. Change a specific color in an image

Solution 2774452

Submitted on 4 Aug 2020
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   Fail
r = ones(100); g = zeros(100); b = zeros(100); cdata = cat(3,r,g,b); c1 = [1 0 0]; c2 = [0 0 1]; cdata_new = cat(3,b,g,r); assert(isequal(changeColor(cdata,c1,c2),cdata_new))

Matrix dimensions must agree. Error in changeColor (line 4) temp{i}(temp{i}==c1) = c2; Error in Test1 (line 8) assert(isequal(changeColor(cdata,c1,c2),cdata_new))

2   Fail
cdata = rand([400,600,3])*0.9; c1 = [0 0.5 1]; c2 = [1 1 1]; assert(isequal(changeColor(cdata,c1,c2),cdata))

Matrix dimensions must agree. Error in changeColor (line 4) temp{i}(temp{i}==c1) = c2; Error in Test2 (line 4) assert(isequal(changeColor(cdata,c1,c2),cdata))

3   Fail
ind = randi(100,[50 1]); c1 = rand([1 3]); c1(3) = 0.95; c2 = [1 1 1]; cdata = rand([100,1,3])*0.8; cdata_new = cdata; for i=1:50 for j=1:3 cdata(ind(i),1,j) = c1(j); cdata_new(ind(i),1,j) = c2(j); end end assert(isequal(changeColor(cdata,c1,c2),cdata_new))

Unable to perform assignment because the left and right sides have a different number of elements. Error in changeColor (line 4) temp{i}(temp{i}==c1) = c2; Error in Test3 (line 12) assert(isequal(changeColor(cdata,c1,c2),cdata_new))