Skip to content
Open

Lab4 #19

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lab01_git/find_duplicates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Declaracion de variables
declare -A arr
shopt -s globstar

# Ciclo for iterativo
for file in **; do
[[ -f "$file" ]] || continue

# Revisa el checksum de cada archivo
read cksm _ < <(md5sum "$file")
if ((arr[$cksm]++)); then
# Si los checksum son iguales imprime el nombre del archivo, es decir los archivos son el mismo.
echo "rm $file"
fi
done

#Extraido de: http://superuser.com/questions/386199/how-to-remove-duplicated-files-in-a-directory
42 changes: 20 additions & 22 deletions lab01_git/questions.md
Original file line number Diff line number Diff line change
@@ -1,71 +1,69 @@
# Warmup Questions

1. What is the clone url of this repository?
> answer
> https://github.com/JaMartinez1423/lab_vision

2. What is the output of the ``cal`` command?

multi
line
answer
> Una matriz con los días y las fechas del presente mes. Esto mostrado en el promt de la terminal.

# Homework Questions

1. What is the ``grep``command?
> answer
> Se utiliza para buscar palabras dentro de un archivo especificado como parámetro de entrada.

2. What is a *makefile*?
> answer
> Es un archivo en donde se especifica una serie de programas que deben ser compilados al ejecutar el comando make.

4. What does the ``-prune`` option of ``find`` do? Give an example
> answer
> Permite encontrar el parámetro de búsqueda sin tener que recorrer cada uno de los directorios.

5. Where is the ``grub.cfg`` file
> answer
> En la carpeta /boot/grub .

6. How many files with ``gnu`` in its name are in ``/usr/src``
> answer
> 0

7. How many files contain the word ``gpl`` inside in ``/usr/src``
> answer
> 0

8. What does the ``cut`` command do?
> answer
> Permite seleccionar la cantidad de caracteres que entra por parámetro.

9. What does the ``wget`` command do?
> answer
> Permite seguir links de internet.

9. What does the ``rsync`` command do?
> answer
> Por medio de un protocolo de transmisión de datos se envían las diferencias entre dos grupos de datos.

10. What does the ``diff`` command do?
> answer
> Este comando permite visualizar las diferencias (lineas añadidas o eliminadas) entre dos archivos.

10. What does the ``tail`` command do?
> answer
> Permite visualizar las ultimas lineas de un archivo.

10. What does the ``tail -f`` command do?
> answer
> Con el parámetro -f se permite monitorear el archivo especificado, mostrado las ultimas lineas cada vez que cambia el mismo.

10. What does the ``link`` command do?
> answer
> Permite enlazar dos archivos, generando cambios en uno cuando el otro es modificado. Esto se hace cambiando la dirección de almacenamiento de uno de los archivos.

11. How many users exist in the course server?
> answer
> 39

12. What command will produce a table of Users and Shells sorted by shell (tip: using ``cut`` and ``sort``)
> answer
> cat /etc/passwd | sort

13. What command will produce the number of users with shell ``/sbin/nologin`` (tip: using ``grep`` and ``wc``)
> answer
> cat /etc/passwd | grep '/sbin/nologin'| wc -l

15. Create a script for finding duplicate images based on their content (tip: hash or checksum)
You may look in the internet for ideas, but please indicate the source of any code you use
Save this script as ``find_duplicates.sh`` in this directory and commit your changes to github

16. What is the meaning of ``#! /bin/bash`` at the start of scripts?
> answer
> Este comienzo le permite saber a Unix con que programa debe ejecutarse el script. Por defecto utilizara bash, de lo contrario el programa especificado.

17. How many unique images are in the ``sipi_images`` database?
> answer
> 301

Binary file added lab3_hybrid/IMG_0537.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lab3_hybrid/IMG_0538.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lab3_hybrid/IMG_0538copy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lab3_hybrid/ImagenHibridaPropia.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 95 additions & 0 deletions lab3_hybrid/ImagenesHibridas.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
%function ImagenesHibridas
function ImagenesHibridas(Image1,Image2)
%Image1 and Image2 are the complete name of the images that are going to be
%mixed.
close all

%Image1 = 'einstein.bmp';
%Image2 = 'marilyn.bmp';

A = imread(Image1);
B = imread(Image2);
% The command imread generates a numeric matrix with the value of each
% channel (R,G,B) of the image.
kernel1 = fspecial('gaussian',[100 100],500);
kernel2 = fspecial('gaussian',[500 500],10000);
% The command fspecial generates a matrix filter with parameters such as,
% the type of the filter, the size of the filter and in this case the
% variance of the gaussian filter. This two filter are high pass filters.
% The parameters specify inside, determines the cut off frecuency.

Af = imfilter(A./2,kernel1);
Bf = (B - imfilter(B,kernel2));
%The command imfilter applies the generate filter with fspecial to the
%image. Like the gaussian filter is a high pass filter, in order to obtein
%a low pass filter it must substract the low frecuency to the original
%image in order to obtein only the high frecuency.

HI = Af + Bf;
% In order to obtein the mixed image, it was requeried to sum the two
% filtered images.
HIC = vis_hybrid_image(HI,[255 255 255]);
% With the function vis_hybrid_image, it could be visualized the piramid. I
% modify this function in order to have another optional parameter, the
% background color of the piramid.

figure
imshow(HI,[])
title([Image1 ' and ' Image2])
figure
imshow(HIC)
title(['Piramid visualization of ' Image1 ' and ' Image2])
% These finals command allow us to visualized the results.
end

function output = vis_hybrid_image(hybrid_image,BackGround_Color)
%visualize a hybrid image by progressively downsampling the image and
%concatenating all of the images together.

% BackGround_color specify the background color of the piramid
% representation. This variable must be a vector of three components, each
% one for each of the RGB channels.
if(nargin == 1)
BackGround_Color = [1 1 1];
end

if(size(BackGround_Color,1)~=1 && size(BackGround_Color,2)~=3)
BackGround_Color = [1 1 1];
elseif(max(BackGround_Color)>255 && min(BackGround_Color)<0)
BackGround_Color = [1 1 1];
end

scales = 5; %how many downsampled versions to create
scale_factor = 0.5; %how much to downsample each time
padding = 5; %how many pixels to pad.
original_height = size(hybrid_image,1);
num_colors = size(hybrid_image,3); %counting how many color channels the input has
output = hybrid_image;
cur_image = hybrid_image;


for i = 2:scales
%add padding
output = cat(2, output, ones(original_height, padding, num_colors));
%dowsample image;
cur_image = imresize(cur_image, scale_factor, 'bilinear');
%pad the top and append to the output
tmp = cat(1,ones(original_height - size(cur_image,1), size(cur_image,2), num_colors), cur_image);
output = cat(2, output, tmp);
end

BackGround_Color = uint8(BackGround_Color);

A = output(:,:,1);
A(A == 1) = BackGround_Color(1);
B = output(:,:,2);
B(B == 1) = BackGround_Color(2);
C = output(:,:,3);
C(C == 1) = BackGround_Color(3);


output(:,:,1) = A;
output(:,:,2) = B;
output(:,:,3) = C;
%code by James Hays extracted from http://cs.brown.edu/courses/cs143/proj1/
end
Binary file added lab3_hybrid/Piramide.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions lab3_hybrid/respuestas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Descripcion de las imagenes

In this lab we use the image IMG_0538.JPG and the image IMG_0538copy.jpg, wich are the final two images that I modified in order to obtein the hibrid image.

## Images

![Mama](IMG_0537.JPG)

The picture above is the original image of my mother. It was taken in my house.

![Hermana](IMG_0538.JPG)

The past picture is the original image of my sister. It was taken in my house. This picture was not modified in order to obtein the hibrid image; it was used as it was shown above.

![MamaMofificada](IMG_0538copy.jpg)

The picture above is the modified picture of my mother used in order to obtein the final hibrid image. It was shiffted to the left in comparison with the original.

![MamaMofificada](ImagenHibridaPropia.jpg)

The past picture was the hibrid result obtein after execute the next command on MATLAB: ``ImagenesHibridas('IMG_0538.JPG','IMG_0538 copy.jpg')``.

![Piramide](Piramide.jpg)

The previous picture was the piramid representation of the hibird image obtein. In the high frecuency region it is observed my mother and in the low frecuency region it is observed my sister.
Because of the size of the images matlab rotate 90 degrees all the images in order to visualize them.
46 changes: 46 additions & 0 deletions lab4_segmentation/segment_by_clustering.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function my_segmentation = segment_by_clustering(I,FS,CM,NC)

% Inputs:
% I : Imagen de entrada en espacio de color RGB
% FS : Feature space
% CM : Clustering method
% NC : Number of clusters

% Outputs:
% my_segmentation

temp = 0;

if(strcmp(FS,'lab'))
I = rgb2lab(I);
elseif(strcmp(FS,'hsv'))
I = rgb2hsv(I);
elseif(strcmp(FS,'rgb+xy'))
temp = 1;
elseif(strcmp(FS,'lab+xy'))
I = rgb2lab(I);
temp = 1;
elseif(strcmp(FS,'hsv+xy'))
I = rgb2hsv(I);
temp = 1;
end

if(temp == 0)
DI = [reshape(I(:,:,1),[1 numel(I)]),reshape(I(:,:,2),[1 numel(I)]),reshape(I(:,:,3),[1 numel(I)])];
else
x = repmat((1:size(I,1))',[size(I,2),1]);
for i=1:numel(I)
y(i,1) = temp;
if(mod(temp,size(I,1))==0)
temp = temp+1;
end
end

DI = [reshape(I(:,:,1),[1 numel(I)]),reshape(I(:,:,2),[1 numel(I)]),reshape(I(:,:,3),[1 numel(I)]),x,y];
end

if(strcmp(CM,'kmeans'))

end

end
23 changes: 23 additions & 0 deletions lab5_bsds/segmentación.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function segmentation(ImagesDir,numCluster)

addpath(genpath(cd));
Images = dir(fullfile(cd,ImagesDir,'*.jpg'));
mkdir(fullfile(cd,'BSDS500','data','images'),'Seg');
addpath(genpath(cd));
oldDir = cd(fullfile(cd,'BSDS500','data','images','Seg'));

for i=1:length(Images)

CellTemp = cell(1,length(numCluster));

for j=1:length(numCluster)
Temp = segment_by_clustering(imread(Images(i).name),'rgb','kmeans',numCluster(j));
CellTemp{1,j} = Temp;
end
name = strcat(Images(i).name(1:end-3),'mat');
save(name,'CellTemp');

clear CellTemp;
end

end
77 changes: 77 additions & 0 deletions lab7_PHOW/ExperimentosDeValidacion.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
clc
clear all
close all

%nTrain = [50,60,70,80];
nTrain = 50;
nClass = [5,50,100,200];
nWords = [300,400,500,600];
nSpatial = {2,4,8,[2,4],[2,4,8]};
C = [10,100,1000,10000];
pHowO = [0,1];

counter = 1;

for p=1:length(nClass)
for s=1:length(nWords)
for t=1:length(nSpatial)
for c=1:length(C)
for q=1:length(pHowO)
close all
temp = nSpatial{t};

tic;
ac(counter)=phow_imagenet_smallValidation(nTrain,nClass(p),nWords(s),...
temp,C(c),pHowO(q));
VecTiempo(counter)=toc;

counter = counter + 1;

clc
p
s
t
c
q

if(length(temp)==1)
Name = strcat('Validation_',num2str(nTrain),'_',...
num2str(nClass(p)),'_',num2str(nWords(s)),'_',...
'[',num2str(temp),']_',num2str(C(c)),'_',...
num2str(pHowO(q)),'_C',num2str(counter-1));
elseif(length(temp)==2)
Name = strcat('Validation_',num2str(nTrain),'_',...
num2str(nClass(p)),'_',num2str(nWords(s)),'_',...
'[',num2str(temp(1)),'_',num2str(temp(2)),']_',...
num2str(C(c)),'_',num2str(pHowO(q)),'_C',num2str(counter-1));
else
Name = strcat('Validation_',num2str(nTrain),'_',...
num2str(nClass(p)),'_',num2str(nWords(s)),'_',...
'[',num2str(temp(1)),'_',num2str(temp(2)),'_',...
num2str(temp(3)),']_',num2str(C(c)),'_',...
num2str(pHowO(q)),'_C',num2str(counter-1));
end

mkdir(fullfile(cd,'imagenet_small'),Name);

Datos = [dir(fullfile(cd,'imagenet_small','*.mat')) ;...
dir(fullfile(cd,'imagenet_small','*.ps'))];

OldDir = cd('imagenet_small');

for i=1:length(Datos)
movefile(Datos(i).name,Name);
end

cd(OldDir);


end
end
end
end
end

OldDir = cd('imagenet_small');
save('Performance','VecTiempo','ac');
cd(OldDir);
Loading