Code Monkey home page Code Monkey logo

blobs-finder's People

Contributors

diogofalken avatar guergeiro avatar

Watchers

 avatar

blobs-finder's Issues

Função a criar um blob para cada pixel

void pesquisarPixeis(struct imagem *imagem, uint row, uint col, uint r, uint g, uint b, uint d, struct blob *blob) {
	// If pixel was already visited
	if (imagem->array_pixeis[row][col].visitado) {
		return;
	}
	// Fails red
	if (abs(imagem->array_pixeis[row][col].r - r) > d) {
		return;
	}
	// Fails green
	if (abs(imagem->array_pixeis[row][col].g - g) > d) {
		return;
	}
	// Fails blue
	if (abs(imagem->array_pixeis[row][col].b - b) > d) {
		return;
	}

	if (!pesquisarPixelBlob(imagem->primeiroBlob, imagem->array_pixeis[row][col])) {
		// Não está em nenhum blob/não existem blobs.
		if (blob) {
			/*
			 * Estamos perante um pesquisa de profundidade de recursividade.
			 * Adicionamos o pixel ao blob (inicio).
			 */
			imagem->array_pixeis[row][col].next = blob->primeiroPixel;
			blob->primeiroPixel = &imagem->array_pixeis[row][col];
		} else {
			/*
			 * Estamos perante a primeira iteração da recursividade.
			 * Cria-se um blob para os pixeis seguintes.
			 */
			blob = calloc(1,sizeof(struct blob));
			blob->primeiroPixel = &imagem->array_pixeis[row][col];
			if (imagem->primeiroBlob) {
				// Já existe um blob, insere no inicio
				blob->next = imagem->primeiroBlob;
			}
			imagem->primeiroBlob = blob;
		}
	}
	// Torna pixel já visitado
	imagem->array_pixeis[row][col].visitado = 1;

	// Pesquisa pixeis adjacentes
	if (row > 0)
		pesquisarPixeis(imagem, row--, col, r, g, b, d, blob);
	if (row < imagem->nlinhas)
		pesquisarPixeis(imagem, row++, col, r, g, b, d, blob);
	if (col > 0)
		pesquisarPixeis(imagem, row, col--, r, g, b, d, blob);
	if (col < imagem->ncolunas)
		pesquisarPixeis(imagem, row, col++, r, g, b, d, blob);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.