image processing - How do I group the pairs of pixels on MATLAB -


i have image read in using imread function. goal collect pairs of pixels in image in matlab. specifically, have read paper, , trying recreate following scenario:

first, original image grouped pairs of pixel values. pair consists of 2 neighboring pixel values or 2 small difference value. pairing done horizontally pairing pixels on same row , consecutive columns, or vertically, or key-based specific pattern. pairing through pixels of image or portion of it.

i looking recreate horizontal pairing scenario. i'm not quite sure how in matlab.

assuming image grayscale, can generate 2d grid of co-ordinates using ndgrid. can use these create 1 grid, shift horizontal co-ordinates right make grid , use sub2ind convert 2d grid linear indices. can use these linear indices create our pixel pairings have described in comments (you should add post btw). what's important need skip on every other column in row ensure unique pixel pairings.

i'm going assume image grayscale. if go colour, more complicated, , i'll leave learning exercise. therefore, assuming image read in through imread , stored in im, this:

[rows,cols] = size(im); [x,y] = ndgrid(1:rows,1:2:cols); ind = sub2ind(size(im), x, y); ind_shift = sub2ind(size(im), x, y+1); pixels1 = im(ind); pixels2 = im(ind_shift); pixels = [pixels1(:) pixels2(:)]; 

pixels 2d array, each row gives pixel intensities of particular pairing in image. bear in mind processed each row independently. such, done 1 row, move on next row , continue procedure. assumes image has even number of columns. should not, have decision make. need either pad image 1 column @ end, , column can want, or can remove column image before processing. if want fill in column, can either make zeroes, or perhaps replicate last column , place beside last column in original image. therefore, appropriate pre-processing step may this:

if mod(cols,2) ~= 0     im = im(:,1:end-1); end 

the above code removes last column in image if number of columns odd. once run through code, can run first bit of code had above.


good luck!


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -