How to Create Alternating Black Columns Across an Image?

조회 수: 4 (최근 30일)
Richard Zareck
Richard Zareck 2017년 9월 10일
댓글: Jose Marques 2017년 9월 10일
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.

채택된 답변

Jose Marques
Jose Marques 2017년 9월 10일
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:
  댓글 수: 6
Richard Zareck
Richard Zareck 2017년 9월 10일
Thank you for your help this works as well!
Jose Marques
Jose Marques 2017년 9월 10일
Nice work!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 9월 10일
  댓글 수: 2
Richard Zareck
Richard Zareck 2017년 9월 10일
I need my picture to look like this
Walter Roberson
Walter Roberson 2017년 9월 10일
clown(:, 1:32:end, :) = 0;
clown(:, 2:32:end, :) = 0;
clown(:, 3:32:end, :) = 0;
...
clown(:, 16:32:end, :) = 0;

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by