Dividir figura em .pnm em fatias
Publicado por Sergio 06/05/2005
[ Hits: 5.666 ]
Este programa dado uma imagem *.pnm em formato p2 (grayscale) faz a divisao em N x M subfiguras. As imagens de saida cujo prefixo para as imagesns de saida e xxx sao colocadas em N x M ficheiros cahamados xxx.1.1.pnm xxx.1.2.pnm ... ... exemplo : divide 2 4 img.pnm out
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXCOL 140
void divide (char *argv[],FILE *f)
{
FILE *z;
int i=0,j,colunas,linhas,imgL,imgA,k,ncoluna=0,nlinha=0,b,v,pixel;
char string [100],strler[100],s[10];
while (fgets (strler,100,f)!=NULL)
{
if (strler[0]!='#')
i++;
if (i==1)
fscanf (f,"%d %d", &imgL, &imgA);
}
rewind (f);
if (atoi (argv[1])>imgA || imgA%atoi (argv[1])!=0 || atoi (argv[2])>imgL || imgL%atoi (argv [2])!=0)
{
fprintf(stderr,"erro, insira multiplos da altura e largura da imagem\n");
exit(2);
}
for (i=1;i<=atoi (argv [1]);i++)
for (j=1;j<=atoi (argv [2]);j++)
{
sprintf (string, "%s.%d.%d.pnm", argv[4], i, j);
if ((z=fopen (string,"a+"))==NULL)
{
fprintf (stderr, "erro a abrir o ficheiro %s",string);
exit (2);
}
k=0;
while ((fgets (strler,100,f)!=NULL) && k<=2)
{
if (strler[0]!='#')
{
if (k==0)
fputs (strler,z);
if (k==1)
fprintf (z,"%d %d\n",imgL/(atoi (argv[2])),imgA/(atoi (argv[1])));
if (k==2)
fputs (strler,z);
k++;
}
else
fputs (strler,z);
}
for (v=nlinha;v<(imgA/(atoi (argv[1]))+nlinha) && (fgets (strler,100,f)!=NULL);v++)
{
for (b=ncoluna;b<(imgL/(atoi (argv[2]))+ncoluna) ;b++)
{
fscanf (f," %d", &pixel);
fflush (f);
sprintf (s,"%d ",pixel);
fputs (s,z);
}
fputc ('\n',z);
}
nlinha+= imgA/(atoi (argv[1]));
ncoluna+= imgL/(atoi (argv[2]));
rewind (f);
fclose (z);
}
}
int main (int argc, char **argv)
{
FILE *f;
char s[MAXCOL];
if (argc !=5)
fprintf (stderr, "erro de sintaxe em %s", argv [0]);
if ((f=fopen(argv[3],"r"))==NULL)
fprintf (stderr, "erro a abrir o ficheiro %s", argv[3]);
divide (argv,f);
return 0;
}
aritmed1.c - Aritmetica de Ponteiros
A máquina nao perdoa (jogo da velha em c -arquivo correto, agora)
Nenhum comentário foi encontrado.
Gentoo: detectando impressoras de rede e como fixar uma impressora por IP
Como o GNOME conseguiu o feito de ser preterido por outras interfaces gráficas
Gentoo binário em 2026: UEFI, LUKS, Btrfs e Systemd
Trabalhando Nativamente com Logs no Linux
Jogando Daikatana (Steam) com Patch 1.3 via Luxtorpeda no Linux
Por que sua empresa precisa de uma PKI (e como automatizar EMISSÕES de certificados via Web API)
Instalando NoMachine no Gentoo com Systemd (acesso Remoto em LAN)
Gentoo: Trocando wpa_supplicant pelo iwd no NetworkManager (Systemd)
O que houve com slackware ??? (12)
Alterar conteúdo de dica [RESOLVIDO] (3)
Vou destruir sua infância:) (5)









