![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/178192/image.png)
How to Create Alternating Black Columns Across an Image?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Richard Zareck
el 10 de Sept. de 2017
Comentada: Jose Marques
el 10 de Sept. de 2017
I have an image X and I would like to create black columns going across the image that are 16 pixels thick with a distance of 16 pixels between each column and I have no idea how to do this. The best I could do was make one column using this line of code:
X(:,1:16,:) = 0;
Also I am not allowed to solve the problem using loops.
0 comentarios
Respuesta aceptada
Jose Marques
el 10 de Sept. de 2017
Hello Richard! You can try this:
size_of_column = 16;
img = imread('image_exemple.jpg');
imshow(img);
mask = zeros(size(img));
for i=1:size(mask,2)
if(mod(round(i/size_of_column),2) == 1)
mask(:,i,:) = 1;
end
end
figure();
img_final(:,:,:) = uint8(double(img(:,:,:)).*mask(:,:,:));
imshow(img_final)
The result:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/178192/image.png)
6 comentarios
Más respuestas (1)
Walter Roberson
el 10 de Sept. de 2017
2 comentarios
Walter Roberson
el 10 de Sept. de 2017
clown(:, 1:32:end, :) = 0;
clown(:, 2:32:end, :) = 0;
clown(:, 3:32:end, :) = 0;
...
clown(:, 16:32:end, :) = 0;
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!