How to create a checker box image of white and black pixels without using inbuilt function?
7 次查看(过去 30 天)
显示 更早的评论
Hello All,
I would like to create an image, that has checker box pattern of black and white pixels.
For ex, How do I create an image of dimensions 1280x960, black and white pixels 16x16 each. Please help.
回答(2 个)
John BG
2016-7-25
编辑:John BG
2016-7-25
Deep
this works
sx=1280;sy=960;
bas=16 % length base square side
% assume sx and sy are multiples of base
Lx=(-1).^[1:1:sx/bas];
Ly=(-1).^[1:1:sy/bas];
A=ones(sx,sy);
[Ai Aj]=ind2sub([sx sy],[1:1:sx*sy]);
Ai2=reshape(Ai,[sx sy]);
Aj2=reshape(Aj,[sx sy]);
linex=[1:bas:sx];linex=[linex sx];
liney=[1:bas:sy];liney=[liney sy];
setx=zeros(1,bas);
for k=2:1:(length(linex)-1)
L1=[linex(k-1):1:(linex(k)-1)]
setx=[setx;L1];
end
setx(1,:)=[];
sety=zeros(1,bas);
for k=2:1:length(liney)-1
L2=[liney(k-1):1:liney(k)-1];
sety=[sety;L2];
end
sety(1,:)=[];
blk=ones(bas,bas);
for k=1:1:sx/bas-1
for s=1:1:sy/bas-1
Lx1=blk*Lx(k);
Ly1=blk*Ly(s);
L12=Lx1.*Ly1;
A(setx(k,:),sety(s,:))=A(setx(k,:),sety(s,:)).*L12;
% A(sety(s,:),setx(k,:))=A(sety(s,:),setx(k,:)).*L12;
end;
end;
check you get a chequered boar with
imshow(A)
every 16x16 block has either +1 or -1
Would you please be so kind to mark my answer as accepted answer
thanks in advance
John BG
0 个评论
TastyPastry
2016-6-3
myIm = uint8(zeros(rows,cols));
myIm = cat(3,myIm+255,myIm,myIm);
imshow(myIm);
1 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Modify Image Colors 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!