matlab - how to covert 1/4 elements of a matrix to zero -
i have 512x512 matrix .i want convert 1/4 elements of matrix 0/how can can help.my program folows
clc; clear all; close all; a=imread('images.jpg'); b=rgb2gray(a); figure,imshow(b); c=double(b); figure,imshow(a); figure,imshow(c); d=rand(512,512); e=exp(2*pi*d); f=c.*e; %figure,imshow(f); g=fft2(f); h=rand(512,512); i=exp(2*pi*h); j=g.*i; k=fft2(j)
%here k matrix of order 512x512.in next step want chanage 1/4 elements ero can help
if want points chosen randomly:
if have 512 x 512 array:
v=randperm(512^2); v=v(1:512*128); k(v)=0;
the above can abbreviated in recent matlab versions
k(randperm(512^2,512*64))=0;
edit
more generally, image array "k"
(case size(k)
nc x nr)
ns = numel(k); v=randperm(ns); v=v(1:round(ns/4)); k(v) = 0;
or in recent version of matlab
ns = numel(k); k(randperm(ns,round(ns/4)))=0;
(case size(k)
nc x nr x 3)
ns = numel(k)/3; v=randperm(ns); v=v(1:round(ns/4)); k(v)=0; k(v+ns)=0; k(v+ns*2)=0;
Comments
Post a Comment