Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Matlab - showBitPlanes

% Ritorna i Bit Plabes dell'immagine a toni di grigio

function showBitPlanes(img)

    imgGray = double( rgb2gray(img) );
    titleString = 'bit planes ';
    
    % MSB ... LSB
    k = 128;
    
    for b=1:8
        
        subplot(2, 4, b);
        imshow( (bitand(imgGray, k) / k) * 255 ); % Fa un and dei bit
        title([titleString int2str(b-1)]);
        k = k/2; % Shifta di 2 i bit
        
    end;
    
return;

getElementsAt //JavaScript Function

This function is able to get all the elements in a specific level of the array

example:

x = [-1, [[8, 22, -7], 32, [[4, 10, -2], 122]], 13];
alert(x.getElementsAt(3));



code:

//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com
Array.prototype.getElementsAt = function(level){
	var r = [], x = [], c = this, l = level, i;
	do
		if(i = c.length, !l)
			for(; i; r[r.length] = c[--i]);
		else
			for(; i; c[--i] instanceof Array && x.push(c[i], l - 1));
	while(l = x.pop(), (c = x.pop()) != undefined);
	return r;
}
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS