C'de görseli yeniden boyutlandırma

Musa B.

Kilopat
Katılım
1 Ekim 2017
Mesajlar
1.633
Makaleler
4
Çözümler
13
Daha fazla  
Cinsiyet
Erkek
Merhaba, verilen bir ödev kapsamında yapacağım işlem için görselin boyutunu küçültmem gerekiyor. Bize gönderilen görsellerin boyutunu küçülterek yapacağımız efektin çıktısını daha anlamlı hale getirmeye çalışacağız. İnternette baya araştırdım fakat elle tutulur bir bilgi bulamadım. 10 yıl önce yazılan bir kodu düzenleyip hatalarını giderip çalıştırdım fakat çıktıyı alamadım.

Şuan elimdeki kod. Kullanılan dil: C.

[CODE lang="c" highlight="43-60"]#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define N 16
void scalePGM(char* infile, char* outfile, float scale);
int main()
{
char infile = "img0.pgm";
char outfile = "scaled.pgm";
void otsu(infile, outfile);
}

void otsu(char* infile, char* outfile)
{
double withinClassVariances[N];
int ncols, nrows, maxvalue;
scalePGM(infile, outfile);
/*
int* histogram = histogram1D(data0, ncols, nrows, N, false);

for (int i = 0; i < N; i++)
withinClassVariances = withinClassVariance(histogram, N, i, false);

int min_index = 0;
double min_val = withinClassVariances[0];
for (int i = 1; i < N; i++) {
if (withinClassVariances < min_val) {
min_val = withinClassVariances;
min_index = i;
}
}

threshold(data0, ncols, nrows, min_index, N);
writePGM(path_out, data0, ncols, nrows);

free(data0);
free(histogram);
*/
}


void scalePGM(char* infile, char* outfile, float scale)
{
FILE* infile_p = fopen(infile, 'r');
FILE* outfile_p = fopen(outfile, 'w');

char* data;
char scaled_data;

while (fread(&data, 1, 1, infile_p) != EOF)
{
scaled_data = (*data) * scale;
fwrite(&scaled_data, 1, 1, outfile);
}

fclose(infile_p);
fclose(outfile_p);
}

/*
int* histogram1D(unsigned char* data, int m, int n, int nbins)
{
int* histogram = (int*)calloc(nbins, sizeof(int));
for (int i = 0; i < ((m) * (n)); i++)


return histogram;
}

double withinClassVariance(int* histogram, int nbins, int threshold)
{
double w_b, mu_b, v_b;
statistics(histogram, nbins, 0, threshold - 1, &w_b, &mu_b, &v_b);
double w_f, mu_f, v_f;
statistics(histogram, nbins, threshold, nbins - 1, &w_f, &mu_f, &v_f);
double v_withinClass = ...;
return v_withinClass;
}


void statistics(int* histogram, int nbins, int binFirst, int binLast, double* w, double* mu, double* v)
{
int histsum =

int totalweights = 0;
for (int i = binFirst; i <= binLast; i++)
totalweights += ...;
*w = (double)totalweights / ...;

int weightedsum = 0;
for (int i = binFirst; i <= binLast; i++)
weightedsum += ...;

if (totalweights) {
*mu = ...;
*v = 0;
for (int i = binFirst; i <= binLast; i++)
*v = ...;
*v = (*v) / (totalweights);
}
}


void threshold(unsigned char* data, int width, int height, unsigned thresh);
*/
[/CODE]
@SideWinder hocam müsaitseniz bakabilir misiniz?
 
Son düzenleme:

Geri
Yukarı