How do I create a black background with a white line?

24 vues (au cours des 30 derniers jours)
Resoa
Resoa le 16 Août 2019
Commenté : Geoff Hayes le 16 Août 2019
Hi, I am currently working on a project dealing with deep learning - however, i am still quite new to matlab. Recently I have been given the task to generate the following picture using matlab but my efforts were to no avail.
333123.jpg
The requirements of this is the background should be of 512x512 pixels and the white line should be of 300 x 2 pixels wide.
Please help me, and many thanks in advance!
  3 commentaires
Resoa
Resoa le 16 Août 2019
Hi, thanks for the reply.
So basically I searched through here and saw someone posting a code similar to the following which I have tweaked to give me 512x512:
backg = uint8(zeros(512,512));
image(backg);
colormap(gray(1));
However I am stucked with the line part. I tried using the cat command but it seem to only gotten no where too..
Geoff Hayes
Geoff Hayes le 16 Août 2019
If you specify backg as a 512x512x3 matrix, then you can avoid the call to colormap.
backg = uint8(zeros(512,512,3));
image(backg);
As for including the white line, you just need to find a starting point and then set that pixel (and the one next to it) to white. In fact, you could set a 302x2 vertical line to all white with one simple command
backg = uint8(zeros(512,512,3));
backg(1:302,200:201,:) = 255;
image(backg);
In the above, we set rows 200 to 201 columns of rows 1 through 302 to white. You should be able to modify the above to create the line that you need.

Connectez-vous pour commenter.

Réponses (1)

KALYAN ACHARJYA
KALYAN ACHARJYA le 16 Août 2019
Modifié(e) : KALYAN ACHARJYA le 16 Août 2019
You can do it multiple ways
image1=zeros(512,512);
m=200;n=200;
image2=rot90(padarray((eye(m,n)),[256-m/2,256-n/2]));
result=image1+image2;
imshow(result);
Do change as per your required result, thats your part?
Or
Pick any pixel positions in mid of the black image, therafter decrese rows and increse columns, the broadening of the line can be achieve using single imdilate command.
More simple answers are also avaliable, Do it on note book (Just matrix manipulation) and implement in Matlab.
  1 commentaire
Resoa
Resoa le 16 Août 2019
Thanks! this works excatly as needed!

Connectez-vous pour commenter.

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by