Split an image into two sets

2 Ansichten (letzte 30 Tage)
Simona Neacsu
Simona Neacsu am 27 Okt. 2019
Kommentiert: Simona Neacsu am 30 Okt. 2019
Hi, I need to split an image into two sets of pixels A and B, each randomly containing half of the pixels (using the rand function). Thanks in advance for any help.

Antworten (1)

Matt J
Matt J am 27 Okt. 2019
N=numel(yourImage);
indices=randperm(N,round(N/2));
A=yourImage(indices);
B=yourImage; B(indices)=[];
  1 Kommentar
Simona Neacsu
Simona Neacsu am 30 Okt. 2019
Thanks! This helped a lot. This is how I finally did it:
randomind=randperm(numel(inital_image), numel(inital_image)/2);
imageA=image1;
imageA(randomind)=0;
imageB=imageA;
for i=1:size(imageA,1)
for j=1:size(imageA,2)
if (imageA(i,j)==0) imageA(i,j)=image1(i,j);
elseif (imageA(i,j)~=0) imageA(i,j)=0; end
end
end

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by