Skip to content

Instantly share code, notes, and snippets.

@panovr
Created July 6, 2012 12:25
Show Gist options
  • Save panovr/3059881 to your computer and use it in GitHub Desktop.
Save panovr/3059881 to your computer and use it in GitHub Desktop.
Gaussian filter with libgil2 and cmlib
1213 910
3
data/input/STA_2713.JPG
data/input/STB_2714.JPG
data/input/STC_2715.JPG
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;
#include <cmlib/image.h>
#include <cmlib/dip.h>
#include <cmlib/imageio/all.h>
#include <cmlib/imageio.h>
using namespace cmlib::image;
using namespace cmlib::dip;
void readImages(vector<ByteImage3> *originalImages) {
FILE *f = fopen("data/input/info.txt", "r");
printf("Reading input image info ...\n");
int nImages, width, height;
fscanf(f, "%d%d%d", &width, &height, &nImages);
printf("\t# of input images: %d\n\tsize: %d x %d\n", nImages, width, height);
for(int i = 0; i < nImages; i++) {
char name[50];
fscanf(f, "%s", name);
printf("\tinput image: %s\n", name);
ByteImage3 img(width, height);
read(img, name);
originalImages->push_back(img);
}
fclose(f);
}
void gaussianFiltering(vector<FloatImage1> *filterImages, const vector<FloatImage1> &grayImages)
{
GaussianFilter<FloatImage1> gaussian(1.5, 1.5);
for(int n = 0; n < grayImages.size(); n++)
{
FloatImage1 img(grayImages[n].width(), grayImages[n].height());
gaussian(grayImages[n], img);
filterImages->push_back(img);
}
}
int main(int argc, char* argv[]) {
printf("Reading input files ...\n");
vector<ByteImage3> originalImages;
readImages(&originalImages);
printf("Produce gray-level input images ...\n");
vector<FloatImage1> grayImages;
for(int i = 0; i < originalImages.size(); ++i) {
FloatImage1 gray = Convert<FloatImage1>()(originalImages[i]);
grayImages.push_back(gray);
}
printf("Performing Gaussian filtering ...\n");
vector<FloatImage1> filterImages;
gaussianFiltering(&filterImages, grayImages);
for (int n = 0; n < filterImages.size(); n++)
{
char name[50];
sprintf(name, "data/filter/i%d_filter.jpg", n + 1);
write(filterImages[n], name);
}
return 0;
}
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;
#include <gil/gil.h>
#include <gil/dip.h>
using namespace gil;
void readImages(vector<ByteImage3> *originalImages) {
FILE *f = fopen("data/input/info.txt", "r");
printf("Reading input image info ...\n");
int nImages, width, height;
fscanf(f, "%d%d%d", &width, &height, &nImages);
printf("\t# of input images: %d\n\tsize: %d x %d\n", nImages, width, height);
for(int i = 0; i < nImages; i++) {
char name[50];
fscanf(f, "%s", name);
printf("\tinput image: %s\n", name);
ByteImage3 img(width, height);
read(img, name);
originalImages->push_back(img);
}
fclose(f);
}
void gaussianFiltering(vector<FloatImage1> *filterImages, const vector<FloatImage1> &grayImages)
{
GaussianFilter<FloatImage1> gaussian(1.5, 1.5);
for(int n = 0; n < grayImages.size(); n++)
{
FloatImage1 img(grayImages[n].width(), grayImages[n].height());
gaussian(img, grayImages[n]);
filterImages->push_back(img);
}
}
int main(int argc, char* argv[]) {
printf("Reading input files ...\n");
vector<ByteImage3> originalImages;
readImages(&originalImages);
printf("Produce gray-level input images ...\n");
vector<FloatImage1> grayImages;
for(int i = 0; i < originalImages.size(); ++i) {
FloatImage1 gray = DefaultConvert<FloatImage1>()(Convert<RgbToGray>()(originalImages[i]));
grayImages.push_back(gray);
}
printf("Performing Gaussian filtering ...\n");
vector<FloatImage1> filterImages;
gaussianFiltering(&filterImages, grayImages);
for (int n = 0; n < filterImages.size(); n++)
{
char name[50];
sprintf(name, "data/filter/i%d_filter.jpg", n + 1);
write(filterImages[n], name);
}
return 0;
}
@Rootex
Copy link

Rootex commented Jul 5, 2014

Hello, i am working with a median filter algorithm, however i cant build it because i am missing the gil/gil.h file. DO you know how i can that?

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