Skip to content

Instantly share code, notes, and snippets.

@pollend
Last active March 5, 2018 20:06
Show Gist options
  • Select an option

  • Save pollend/55cff1cdfbb01aa74e2ea2de3748c9bf to your computer and use it in GitHub Desktop.

Select an option

Save pollend/55cff1cdfbb01aa74e2ea2de3748c9bf to your computer and use it in GitHub Desktop.
from = double(imread('Cat.jpg'));
to = double(imread('Moon.jpg'));
h = figure;
image = imshow(uint8(from));
max = 30;
for i = 0:max
output = uint8(from + (((to - from)/max) * i));
set(image,'CData',output);
result = getframe(h);
im = frame2im(result);
[imind,cm] = rgb2ind(im,256);
if i == 0
imwrite(imind,cm,'final.gif','gif','LoopCount',Inf,'DelayTime',.1);
else
imwrite(imind,cm,'final.gif','gif','WriteMode','append','DelayTime',.1);
end
end
from = imread('Cat.jpg');
pic = ((from > 100) * 255);
WIN = 80;
[sizex, sizey] = size(pic);
posxx = 87;
posyy = 122;
section = pic(posyy:posyy+WIN-1,posxx:posxx+WIN-1);
pad_pic = zeros(sizex + WIN,sizey + WIN,'uint8');
pad_pic((WIN/2):(WIN/2)+sizey-1,((WIN/2):(WIN/2)+sizex-1)) = pic;
subplot(1,2,1);
imshow(section);
subplot(1,2,2);
imshow(pic);
count = 0;
for x = 1:sizex
for y = 1:sizey
match = (pad_pic(y:y+WIN-1,x:x+WIN-1) == section);
percent_match = double(sum(sum(match)))/(WIN*WIN);
if(percent_match > .98 && count < 100)
count = count + 1;
fprintf("match"+count+ ":" + (x-(WIN/2)) + "," + (y-(WIN/2))+ "--" + percent_match + "\n");
rectangle('Position',[x-(WIN/2),y-(WIN/2),WIN,WIN], 'EdgeColor','red')
end
end
end
%rectangle('Position', [100 100 200 200], 'FaceColor', [0 0 1 0.5])
image = double(imread('Cat.jpg'));
[width,height] = size(image);
output = image;
single = reshape(image, 1, []);
freq = [1:255];
for n = 0:255
freq(n+1) = length(find(single == n))/ (width* height);
end
for x = 1:width
for y = 1:height
output(x,y) = sum(freq(1:(image(x,y)+1)));
end
end
% matlab uint8 already rounds up/down if over .5
output = uint8(255 * output );
image = uint8(image);
subplot(1,2,1);
imshow(uint8(image));
subplot(1,2,2);
imshow(output);

Exercise 1: Fading of Images

The fading of images is a special effect that is used daily in motion features and big screen movies. The fading of one image to another is implemented simply using a pixel by pixel comparison of the two original images. Write a Matlab program that implements the fading algorithm from an initial image to a destination image. Use the Matlab function ‘drawnow’ to display the intermediate images of the fade.

Exercise 2: Binary Template Matching

Write a program to find instances of your template in the image using the Binary Template Matching algorithm discussed in class. You will have to design the template yourself based on an analysis of the image. If J = MATCH(I1,I2), then M2(I1,I2) = over all rows and columns of J. Apply the match measure M₂ at every pixel in the input image where a sufficiently large neighborhood exists. Construct an output image J₁ where each pixel is equal to the match measure M₂ (set J₁ equal to zero at pixels where a sufficiently large neighborhood does not exist in the input image). Threshold the image J₁ to obtain a binary image J₂ that should be equal to logical zero at pixels where there is a high probability that your template is present in the input image. Display the original image, the template, J₁ and J₂.

Exercise 3: Histogram Equalization

Write a program to perform histogram equalization on images. Turn in your Matlab code, printouts of the original and equalized image(s), and histograms of the original and equalized image(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment