matlab - How can I traverse through pixels? -


suppose, have following image in hand.

enter image description here

i have marked pixels of image follows,

enter image description here

now, have obtained pixel mask,

enter image description here

how can traverse through pixels in mask?

the original question:

how can save pixels interested in?
...
question: now, in step#2, want save pixels in data-structure (or, whatever) d can apply function f2(i, d, p,q,r) on image on basis of pixels d.

create binary mask

try using logical mask of image keep track of pixels of interest.

i'll make random image example here:

randimg = rand(64,64,3); imgmask = false(size(randimg(:,:,1))); imgmask(:,[1:4:end]) = true; % take every 4 columns d.  % show talking maskimg = zeros(size(randimg)); imgmaskforrgb = repmat(imgmask,1,1,3); maskimg(imgmaskforrgb) = randimg(imgmaskforrgb);  figure('name','psychadelic'); subplot(2,1,1); imagesc(randimg); title('random image'); subplot(2,1,2); imagesc(maskimg); title('masked pixels of interest'); 

here's looks like: enter image description here

it determine how store , use image mask (d in case) not sure how functions written. example give understanding of how can done though.

edit

you added second question since posted:

but, problem is, how going traverse through pixels in k?

vectrorization

to set pixels white:

randimg(imgmaskforrgb) = 255;

in example, accessed of pixels of interest @ same time mask in vectorized fashion.

i translated 2d mask 3d mask, in order grab rgb values of each pixel. code:

  maskimg = zeros(size(randimg));   imgmaskforrgb = repmat(imgmask,1,1,3); 

then access of these pixels in image of interest, used call:

  randimg(imgmaskforrgb) 

these pixels of interest. if want divide these values in 1/2 this:

  randimg(imgmaskforrgb) = randimg(imgmaskforrgb)/2; 

loops

if want traverse, 1 pixel @ time, can use double loop:

 r=1:size(randimg,1)     c=1:size(randimg,2)          if(imgmask(r,c))  % traverse pixels              curpixel = randimg(r,c,:);  % grab ones flagged          end     end  end 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -