How do I create a black background with a white line?
21 views (last 30 days)
Show older comments
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.
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 Comments
Geoff Hayes
on 16 Aug 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.
Answers (1)
KALYAN ACHARJYA
on 16 Aug 2019
Edited: KALYAN ACHARJYA
on 16 Aug 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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!