Draw a binary image

I want to draw an image of vertical stripes using the pattern 11001100111000. If 1 represents a black bar and 0 represents a white bar, how can I draw a black and white image using black with an intensity value of 0 and white with an intensity value of 1? Assume the image is 100 pixels long and assume 1 pixel is 1 bar.
An example of a code would be great, thanks.

1 个评论

How could the image have 100 pixels with one pixel per bar, if the pattern has 14 elements only?

请先登录,再进行评论。

回答(3 个)

image_i_want = [1 1 0 0 1 1 0 0 1 1 1 0 0 0 ...put in the rest of your pattern... ];
imagesc(image_i_want)
You probably want a more complicated answer...

1 个评论

I'll just say, augment the code from @Iain with,
>> colormap gray >> imagesc(image_i_want)
@Anna if you want more control of rectangle objects, borders, shading, filling etc, look at http://www.mathworks.com/help/matlab/ref/rectangle.html to get your b/w images.

请先登录,再进行评论。

Try this:
desiredOutputColumns = 640; % Whatever....
desiredOutputRows = 480; % Whatever.....
pattern = [1,1,0,0,1,1,0,0,1,1,1,0,0,0];
stripeImage = imresize(pattern, [desiredOutputRows, desiredOutputColumns], 'nearest');
imshow(stripeImage, [])
I'm not sure if you want 0 to be black and 1 to be white, or vice versa - your message was ambiguous on tat point. Anyway, it's trivial to adapt the above code.

20 个评论

According to your code, 0 is for black and 1 is for white and suppose if we want reverse of this. Then what changes have to we apply?
Could you help me out here?
0 is for 0 and 1 is for 1. If you want it to be displayed inverted, invery the image inside imshow
imshow(~stripeImage);
I don't know. Maybe you could have a lens system to focus a monitor onto a surface and then just put stripes into the monitor's display.
Yes you are correct. physically it is the way.
But my work is manually and by on MATLAB programming.
  1. Generate the Cube structure and generate the stripes with a fix period.
  2. geomatric calculation of stripe pattern of cube. For this I have to take bird view. Suppose cube is on the plane and when we put stripes on the cube. The pattern will get distorted.
For every pixel of the image, I have to calculate stripe pattern and collect 3D points and then later I will do reconstruction of that object.
So can you give me some starting and some suggestions. Or may be some literature work. I have got the idea but don't know how to start excatly.
Thanks.
So you're wanting more computer graphics and modeling and image synthesis/generation, rather than image analysis. I don't have any tips for you since I don't do that kind of graphics. For what it's worth you might try searching the image processing literature here:
Okah Thanks.
Can you tell me
  1. how to generate rectangualr stripes with fix period.And Width of the stripes should be half of the period.
  2. how to generate 3D cube by matlab image processing tool?
I don't know off the top of my head. I'd have to figure it out just as you'll have to, so I'll let you do that. Search the forum for "cube" and "stripes". That's what I'd do.
function plot_3d_cube(theta,varargin) %%theta in radian
H=[0 0.3 0 0.3 0 0.3 0 0.3; 0 0 0.3 0.3 0 0 0.3 0.3; 0 0 0 0 0.3 0.3 0.3 0.3]; %Vertices of the cube
S=[1 2 4 3; 1 2 6 5; 1 3 7 5; 3 4 8 7; 2 4 8 6; 5 6 8 7]; %Surfaces of the cube
figure(1)
hold on
H1 = zeros(size(S,1),5) ;
H2 = zeros(size(S,1),5) ;
H3 = zeros(size(S,1),5) ;
for i=1:size(S,1)
Si=S(i,:);
fill3(H(1,Si),H(2,Si),H(3,Si),'w','facealpha',0.1)
end
axis equal, axis on, hold off, view(20,10)
this is the code to generate the cube. Can you tell how to show the generated image by imshow command. Because i need matrix of the cube image.
@Ayush singhal, imshow() works with digital images, not computer graphics. Also, imshow() itself generates/shows the displayed image in the current or specified axes. So it shows it itself. imshow() does not create a variable that then needs to be shown by some other function (if that's what you were thinking).
If you want, you can use exportgraphics() to turn the axes into a digital image and save it as a PNG format image file on disk. You can then treat it as a digital image and use that file name with imread() to read it in from disk, and then use imshow() to display the variable as a digital image.
Okah I like this idea. So after doing this, The matrix poitns would be change. Is it or not?
Not sure I understand the question. exportgraphics is like you just hit PrintScreen to copy the figure to the clipboard and then wrote it to disk. It does not save any matrix points, data, axes properties (like their size, line width, colors, etc.).
red = repmat(uint8([0 1 0]), 10,10);
cmap = [0 0 0;1 1 1;0 0 0];
image(red);
colormap(cmap);
axis ([0 30 0 10])
in this script, can you tell me how to change the stripe width?
Try this:
screenSize = get(0,'Screensize')
screenWidth = screenSize(3)
screenHeight = screenSize(4)
stripeWidth = 100; % Pixels
oneCycle = repelem([0, 1], stripeWidth);
% Make vertical stripes.
numStripes = floor(screenWidth / (2 * stripeWidth))
multipleCycles = uint8(255 * repmat(oneCycle, [screenSize(4), numStripes]));
cmap = [0 0 0; 1 0 0];
imshow(multipleCycles, [], 'ColorMap', cmap);
axis('on', 'image');
g = gcf;
g.Position = screenSize; % Enlarge figure to full screen.
fprintf('Done running %s.m\n', mfilename);
Ayush singhal
Ayush singhal 2021-4-26
编辑:Ayush singhal 2021-4-26
Thanks I got the idea.
In the above code, I changed the stripe width so number of stripes has also changed but axis location is still same.
I have set the axis limit but it is not working here.
@Ayush singhal, if you have some question for me, please state it explicitly and attach your code. Otherwise I'll assume you're going to get it working yourself.
@Image Analyst , hello is it possible to stripes the light projection on a image plane?
Here in this below picture, one can see the stripe pattern on the image plane. I would like something like this pattern but this should be projected. It means only stripes will be there on the plane, not a complete figure.
I have attached a code file also. Please any lead would be helpful.
( in this picture, the stripe pattern code figure is overlaped on the plane.)
@Ayush singhal, the code in my answer creates a stripe image. You can then project it if you have a projector. To make it fullscreen, do
g = gcf;
g.WindowState = 'maximized'
To make the smaller, thinner lines, you can use yline() and xline() in a loop.
hello I would like to generate a stripe pattern as an image (pixel) with the cube.
For this I need a programme to detect the shift in the stripes whihc are over the cube.
Is it possible?
@Ayush singhal, probably, though I'm not going to have time to figure it out for you, sorry.
Okah Thanks.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Display Image 的更多信息

提问:

2013-8-30

Community Treasure Hunt

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

Start Hunting!

Translated by