So this is pretty much a follow-up question to this one I asked yesterday, but now I'm interested in cropping coloured padding (attachment for test-image-2.jpg). With the answer from Walter on the previous question, I tried to do it like this:
I = imread('test-image-2.jpg'); rI = I(:,:,1); gI = I(:,:,2); bI = I(:,:,3); Rw = all(rI == 237); %red channel value
Gw = all(gI == 27); %green channel value
Bw = all(bI == 36); %blue channel value
%mask
Rmaskc = all(Rw, 1);Rmaskr = all(Rw, 2); Gmaskc = all(Gw, 1);Gmaskr = all(Gw, 2); Bmaskc = all(Bw, 1);Bmaskr = all(Bw, 2); %set to 0
rJ = rI; rJ(Rmaskr,:,:) = 0; rJ(:,Rmaskc,:) = 0; gJ = gI; gJ(Gmaskr,:,:) = 0; gJ(:,Gmaskc,:) = 0; bJ = bI; bJ(Bmaskr,:,:) = 0; bJ(:,Bmaskc,:) = 0; %RED
rJ( ~any(rJ,2), : ) = []; %rows
rJ( :, ~any(rJ,1) ) = []; %columns
%GREEN
gJ( ~any(gJ,2), : ) = []; %rows gJ( :, ~any(gJ,1) ) = []; %columns %BLUE
bJ( ~any(bJ,2), : ) = []; %rows bJ( :, ~any(bJ,1) ) = []; %columns IM = cat(3, rJ, gJ, bJ);
It crops the sides just fine (the small strokes on sides have different RGB values so guess thats ok), but the top/bottom is not getting cropped.
So I'm a bit confused on why the sides get cropped decently, but for some reason the top/bottom gets ignored
Best Answer