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

19 次查看(过去 30 天)
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 个评论
Resoa
Resoa 2019-8-16
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 2019-8-16
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.

请先登录,再进行评论。

回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-8-16
编辑:KALYAN ACHARJYA 2019-8-16
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.

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by