How to create a checker box image of white and black pixels without using inbuilt function?

4 ビュー (過去 30 日間)
Deep P
Deep P 2016 年 6 月 3 日
コメント済み: DGM 2023 年 2 月 20 日
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
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

TastyPastry
TastyPastry 2016 年 6 月 3 日
myIm = uint8(zeros(rows,cols));
myIm = cat(3,myIm+255,myIm,myIm);
imshow(myIm);
  1 件のコメント
DGM
DGM 2023 年 2 月 20 日
That doesn't actually answer the question. That just creates a solid red image.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeModify Image Colors についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by