Skip to content

Instantly share code, notes, and snippets.

@robie2011
Last active November 25, 2017 16:30
Show Gist options
  • Save robie2011/296043a447dd85efcefcd3c8519dd9f3 to your computer and use it in GitHub Desktop.
Save robie2011/296043a447dd85efcefcd3c8519dd9f3 to your computer and use it in GitHub Desktop.
imread
imwrite
imhist
imfinfo % fileinfo
imgetfile
imshow(I, [low high]) %show all values =< low and >= high
%convert matrix values to intensity values between 0 and 1
I = mat2gray(A,[AMIN AMAX])
im2bw
im2double
im2uint8(I) %Convert image to 8-bit unsigned integers
% array operation
v = round(rand(1,5)*100)
>> v = round(rand(1,10)*100)
v =
14 42 92 79 96 66 4 85 93 68
>> v(3:3)
ans =
92
>> v(3:4)
ans =
92 79
>> v(8:end)
ans =
85 93 68
% start start at position 1, and take every 5th element till end
>> v(1:5:end)
ans =
14 66
%do the same reverse ...
>> v(end:-5:1)
ans =
68 96
% creates n values between a and b
% linspace(a,b,n)
>> linspace(0,5,3)
ans =
0 2.5000 5.0000
%generators
rand %uniformly distributed
randn % normally distributed (gaussian 0 and variance 1)
ones
zeros
true
false
magic
%image operations
imadd
imsubtract
immultiply
imdivide
imabsdiff
imcomplement
imlincomb % linear combination of two or more images
%queries
all() % all values are > 0
any % any value is > 0
xor % both operand are logically different
I = imread('rose.tif');
%a=round(rand(4,4)*100)
k=uint8( down_Scaling(I, 0.5));
imshow(k)
figure
imshow(I)
function z = down_Scaling(I, factor)
I_new = zeros(size(I)*factor);
[width_orig,height_orig] = size(I);
rIndex=1;
for r=1:inv(factor):height_orig
cIndex = 1;
for c=1:inv(factor):width_orig
I_new(rIndex,cIndex) = I(r,c);
cIndex = cIndex + 1;
end
rIndex = rIndex + 1;
end
z = I_new;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment