Excluding white squares from a scrambled image
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi There,
So I have a piece of code which should chop up squares of an image and scramble them. I have a series of faces which are on a white background. What I am trying to do is take a random square from a random image to add to a final scrambled image, but not if that square is white.
This is the code:
%% first getting the size of the image and dividing it into blocks of 30 pixels
n = 30;
image_size = imread(all_images{1});
mn = floor(size(image_size)/n);
m1 = mn(1);
n1 = mn(2);
% a new matrix for the scrambled blocks to go in
newim = zeros(m1*n,n1*n);
% there are 51 images in the file
for bb = 1:51
for k = 1:m1*n1
good_squares = false;
while ~good_squares
current_image = randsample(1:51, 1);
my_image = imread(all_images{current_image});
ind = randperm(m1*n1);
[ind1, ind2] = ind2sub([m1, n1], ind);
[i,j]=ind2sub([m1, n1], k);
newim((i-1)*n+1:i*n, (j-1)*n+1:j*n) = ...
my_image((ind1(k)-1)*n+1:ind1(k)*n,(ind2(k)-1)*n+1:ind2(k)*n);
x = my_image((ind1(k)-1)*n+1:ind1(k)*n,(ind2(k)-1)*n+1:ind2(k)*n);
good_squares = true;
if x(1, 1) == 255 && x(1, 30) == 255 && x(30, 1) == 255
good_squares = false;
elseif x(1, 1) == 255 && x(1, 30) == 255 && x(30, 30) == 255
good_squares = false;
elseif x(30, 1) == 255 && x(30, 30) == 255 && x(1, 30) == 255
good_squares = false;
end
end
end
% write out new mask
imwrite(newim, ['mask' num2str(bb) '.bmp'],'bmp');
end
So where I run the exclusion portion of the code (good_blocks = false) I am trying to exclude a block if the pixels in three of the corners are white. This code spits out 51 pure white images, so either the indexing is broken, or the while loop is not right. Any suggestions on how to do this is appreciated.
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!