void	ImageBaseTest::testPixeloffset() {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testPixelOffset() begin");
	CPPUNIT_ASSERT(i1->pixeloffset(4, 11) == (4 + 11 * 640));
	CPPUNIT_ASSERT(i1->pixeloffset(ImagePoint(4, 11)) == (4 + 11 * 640));
	CPPUNIT_ASSERT(i4->pixeloffset(4, 11) == (4 + 1024 * (11)));
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testPixelOffset() end");
}
예제 #2
0
void Integral::PrepareFor(ImageBase& Source)
{
   ImageProgram::PrepareFor(Source);

   // Also build float program as we will need it
   GetProgram(Float).Build();

   SSize VerticalImgSize = {GetNbGroupsW(Source) - 1, Source.Height()};
   SSize HorizontalImgSize = {Source.Width(), GetNbGroupsH(Source) - 1};

   if (VerticalImgSize.Width == 0)
      VerticalImgSize.Width = 1;

   if (HorizontalImgSize.Height == 0)
      HorizontalImgSize.Height = 1;

   // Check validity of current temp buffers
   if (m_VerticalJunctions != nullptr && 
      uint(VerticalImgSize.Width) <= m_VerticalJunctions->Width() &&
      uint(VerticalImgSize.Height) <= m_VerticalJunctions->Height() &&
      uint(HorizontalImgSize.Width) <= m_HorizontalJunctions->Width() &&
      uint(HorizontalImgSize.Height) <= m_HorizontalJunctions->Height() &&
      Source.IsFloat() == m_VerticalJunctions->IsFloat())
   {
      // Buffers are good
      return;
   }

   // Create buffers for temporary results
   m_VerticalJunctions = std::make_shared<TempImage>(*m_CL, VerticalImgSize, SImage::F32);
   m_HorizontalJunctions = std::make_shared<TempImage>(*m_CL, HorizontalImgSize, SImage::F32);
}
예제 #3
0
	void ProcessTimerTick(void)
	{
		if (m_visible && m_img && --m_counter <= 0) {
			m_nFramePosition = m_img->SelectNextFrame(m_nFramePosition);
			long frtm = m_img->GetFrameDelay();
			m_counter = frtm / 10 + ((frtm % 10) >= 5);

			switch (m_animtype) {
			case animStdOle:
				if (m_allowAni) SendOnViewChange();
				else {
					m_visible = false;
					UnloadSmiley();
				}
				m_allowAni = false;
				break;

			case animDrctRichEd:
				DrawOnRichEdit();
				break;

			case animHpp:
				DrawOnHPP();
				break;
			}
		}
	}
예제 #4
0
HICON SmileyType::GetIconDup(void)
{
	ImageBase* img = CreateCachedImage();
	img->SelectFrame(m_index);
	HICON hIcon = img->GetIcon();
	img->Release();
	return hIcon;
}
void	ImageBaseTest::testAccessors() {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testAccessors() begin");
	CPPUNIT_ASSERT(i1->size() == ImageSize(640,480));
	CPPUNIT_ASSERT(i2->size() == ImageSize(640,480));
	CPPUNIT_ASSERT(i3->size() == ImageSize(1024,768));
	CPPUNIT_ASSERT(i4->size() == ImageSize(1024,768));
	debug(LOG_DEBUG, DEBUG_LOG, 0, "testAccessors() end");
}
예제 #6
0
void CheckSizeAndType(const ImageBase& Img1, const ImageBase& Img2)
{
   CheckCompatibility(Img1, Img2);

   if (Img1.Depth() != Img2.Depth())
      throw cl::Error(CL_INVALID_VALUE, "Different image depth used");

   if (Img1.IsUnsigned() != Img2.IsUnsigned())
      throw cl::Error(CL_INVALID_VALUE, "Different image types used");
}
예제 #7
0
HBITMAP SmileyType::GetBitmap(COLORREF bkgClr, int sizeX, int sizeY)
{
	ImageBase* img = CreateCachedImage();
	if (!img) return NULL;
	img->SelectFrame(m_index);
	HBITMAP hBmp = img->GetBitmap(bkgClr, sizeX, sizeY);
	img->Release();

	return hBmp;
}
예제 #8
0
void CheckCompatibility(const ImageBase& Img1, const ImageBase& Img2)
{
   CheckSameSize(Img1, Img2);

   if (Img1.IsFloat() != Img2.IsFloat())
      throw cl::Error(CL_INVALID_VALUE, "Different image types used");

   if (Img1.IsUnsigned() != Img2.IsUnsigned())
     throw cl::Error(CL_INVALID_VALUE, "Different image types used");
}
예제 #9
0
	STDMETHOD(Draw)(DWORD dwAspect, LONG, void*, DVTARGETDEVICE*, HDC, 
		HDC hdc, LPCRECTL pRectBounds, LPCRECTL /* pRectWBounds */,
		BOOL (__stdcall *)(ULONG_PTR), ULONG_PTR) 
	{
		if (dwAspect != DVASPECT_CONTENT) return DV_E_DVASPECT;
		if (pRectBounds == NULL) return E_INVALIDARG;

		LoadSmiley();

		if (m_img == NULL) return E_FAIL;

		m_sizeExtent.cx = pRectBounds->right  - pRectBounds->left;
		m_sizeExtent.cy = pRectBounds->bottom - pRectBounds->top;

		m_rectExt = m_sizeExtent;

		switch (m_animtype) {
		case animDrctRichEd: 
			{
				m_rectExt.cy = pRectBounds->bottom - m_rectOrig.y;
				RECT frc = { 0, 0, m_sizeExtent.cx - 1, m_sizeExtent.cy - 1 };

				HBITMAP hBmp = CreateCompatibleBitmap(hdc, frc.right, frc.bottom);
				HDC hdcMem = CreateCompatibleDC(hdc);
				HANDLE hOld = SelectObject(hdcMem, hBmp);

				HBRUSH hbr = CreateSolidBrush(m_bkg); 
				FillRect(hdcMem, &frc, hbr);
				DeleteObject(hbr);

				m_img->DrawInternal(hdcMem, 0, 0, frc.right, frc.bottom);

				BitBlt(hdc, pRectBounds->left, pRectBounds->top, frc.right, frc.bottom, hdcMem, 0, 0, SRCCOPY);

				SelectObject(hdcMem, hOld);    
				DeleteObject(hBmp);	
				DeleteDC(hdcMem);
			}
			GetDrawingProp();
			break;

		case animHpp:
			m_orect = *(LPRECT)pRectBounds;

		default:
			m_img->DrawInternal(hdc, pRectBounds->left, pRectBounds->top, 
				m_sizeExtent.cx - 1, m_sizeExtent.cy - 1);
			break;
		}

		m_allowAni  = true;
		m_visible = true;

		return S_OK;
	}
예제 #10
0
HICON SmileyType::GetIcon(void)
{
	if (m_SmileyIcon == NULL) {
		ImageBase* img = CreateCachedImage();
		if (!img) return NULL;
		img->SelectFrame(m_index);
		m_SmileyIcon = img->GetIcon();
		img->Release();
	}
	return m_SmileyIcon;
}
예제 #11
0
void SmileyType::GetSize(SIZE& size)
{
	if (m_size.cy == 0) {
		ImageBase* img = CreateCachedImage();
		if (img) {
			img->GetSize(m_size);
			img->Release();
		}
	}
	size = m_size;
}
예제 #12
0
void DisplayImpl::drawImage(Point p, const ImageBase& img)
{
    short int xEnd=p.x()+img.getWidth()-1;
    short int yEnd=p.y()+img.getHeight()-1;

    //Qt backend is meant to catch errors, so be bastard
    if(xEnd >= width || yEnd >= height)
        throw(logic_error("Image out of bounds"));

    img.draw(*this,p);
    beginPixelCalled=false;
}
예제 #13
0
int ImageBase::diff(ImageBase seuille, ImageBase dilate){
	unsigned char* dataS = seuille.getData();
	unsigned char* dataD = dilate.getData();
	unsigned char* data = this->getData();

	for(int i = 0; i < this->getTotalSize(); i++){
		if(dataS[i] == dataD[i]){
			data[i] = 255;
		}else{
			data[i] = 0;
		}
	}
	return 0;
}
예제 #14
0
bool SameType(const ImageBase& Img1, const ImageBase& Img2)
{
   return (Img1.IsFloat() == Img2.IsFloat() &&
      Img1.IsUnsigned() == Img2.IsUnsigned() &&
      Img1.Depth() == Img2.Depth() &&
      Img1.NbChannels() == Img2.NbChannels());
}
예제 #15
0
void ImageProximityFFT::PrepareFor(ImageBase& Source, Image& Template)
{
   SSize size;

   size.Width = Source.Width();
   size.Height = Source.Height();

   if (m_image_sqsums == nullptr || m_image_sqsums->Width() < size.Width || m_image_sqsums->Height() < size.Height)
      m_image_sqsums = std::make_shared<TempImage>(*m_CL, size, SImage::F32, Source.NbChannels());


   // Size of the FFT input and output
   size.Width = Source.Width() + Template.Width() / 2;
   size.Height = Source.Height() + Template.Height() / 2;

   // Search for a size supported by clFFT
   while (!m_fft.IsSupportedLength(size.Width))
      size.Width++;

   while (!m_fft.IsSupportedLength(size.Height))
      size.Height++;

   if (m_bigger_source == nullptr || m_bigger_source->Width() != size.Width || m_bigger_source->Height() != size.Height)
      m_bigger_source = std::make_shared<TempImage>(*m_CL, size, SImage::F32, 1);

   if (m_bigger_template == nullptr || m_bigger_template->Width() < size.Width || m_bigger_template->Height() < size.Height)
      m_bigger_template = std::make_shared<TempImage>(*m_CL, size, SImage::F32, 1);



   // Size of the spectral images
   size.Width = size.Width / 2 + 1;

   if (m_templ_spect == nullptr || m_templ_spect->Width() < size.Width || m_templ_spect->Height() < size.Height)
      m_templ_spect = std::make_shared<TempImage>(*m_CL, size, SImage::F32, 2);

   if (m_source_spect == nullptr || m_source_spect->Width() != size.Width || m_source_spect->Height() != size.Height)
      m_source_spect = std::make_shared<TempImage>(*m_CL, size, SImage::F32, 2);

   if (m_result_spect == nullptr || m_result_spect->Width() < size.Width || m_result_spect->Height() < size.Height)
      m_result_spect = std::make_shared<TempImage>(*m_CL, size, SImage::F32, 2);

   m_integral.PrepareFor(Source);
   m_statistics.PrepareFor(Template);
   m_transform.PrepareFor(Source);
   m_fft.PrepareFor(*m_bigger_source, *m_source_spect);
   SelectProgram(Source).Build();
   SelectProgram(*m_source_spect).Build();
}
예제 #16
0
	void DoDirectDraw(HDC hdc)
	{
		HBITMAP hBmp = CreateCompatibleBitmap(hdc, m_rectExt.cx, m_rectExt.cy);
		HDC hdcMem = CreateCompatibleDC(hdc);
		HANDLE hOld = SelectObject(hdcMem, hBmp);

		RECT rc;
		rc.left   = m_rectExt.cx - m_sizeExtent.cx;
		rc.top    = m_rectExt.cy - m_sizeExtent.cy;
		rc.right  = rc.left + m_sizeExtent.cx;
		rc.bottom = rc.top + m_sizeExtent.cy;

		HBRUSH hbr = CreateSolidBrush(m_bkg); 
		RECT frc = { 0, 0, m_rectExt.cx, m_rectExt.cy };
		FillRect(hdcMem, &frc, hbr);
		DeleteObject(hbr);

		m_img->DrawInternal(hdcMem, rc.left, rc.top, m_sizeExtent.cx - 1, m_sizeExtent.cy - 1); 

		if (m_richFlags & REO_SELECTED) {
			HBRUSH hbr = CreateSolidBrush(m_bkg ^ 0xFFFFFF); 
			FrameRect(hdcMem, &rc, hbr);
			DeleteObject(hbr);
		}

		if (m_richFlags & REO_INVERTEDSELECT)
			InvertRect(hdcMem, &rc);

		BitBlt(hdc, m_rectOrig.x, m_rectOrig.y, m_rectExt.cx, m_rectExt.cy, hdcMem, 0, 0, SRCCOPY);

		SelectObject(hdcMem, hOld);    
		DeleteObject(hBmp);	
		DeleteDC(hdcMem);
	}
예제 #17
0
static std::string SelectName(const char * Name, const ImageBase& Img)
{
   if (Img.NbChannels() != 1)
      throw cl::Error(CL_IMAGE_FORMAT_NOT_SUPPORTED, "Filters on images with >1 channels not yet supported");

   return std::string(Name) + "_1C";
}
예제 #18
0
/**
Déségalise une image en utilisant la fonction de répartition inverse d'une autre image.
**/
int ImageBase::desegaliser(ImageBase img){
	unsigned char* data = this->getData();
	double F[256];
	img.getFa(F);
	int indice = 0;
	double tmp = 0., space = 1000., current = 0.;
	
	cout << "test1" << endl;
	for(int i = 0; i < this->getTotalSize(); i++){
		current = (double)data[i]/(double)255.;
		for(int j = 0; j < 256; j++){
			tmp = current - F[j];
			if(tmp < 0.)
				tmp *= -1.;
				
			if(tmp < space){
				space = tmp;
				indice = j;
			}
		}
		data[i] = (unsigned char)(F[indice]*255.);
		space = 1000.;
		tmp = 0.;
		indice = 0;
	}
	cout << "test2" << endl;
	return 0;
}
예제 #19
0
파일: profil.cpp 프로젝트: Arihy/TPM
int main(int argc, char **argv)
{
	///////////////////////////////////////// Exemple d'un seuillage d'image
	char cNomImgLue[250];
	char info;
	int indice;
  
	if(argc != 4) 
	{
		printf("Usage: ImageIn.pgm C(ou L) Indice \n"); 
		return 1;
	}
	sscanf (argv[1],"%s",cNomImgLue);
	sscanf (argv[2],"%c",&info);
	sscanf (argv[3],"%d",&indice);

	
	//ImageBase imIn, imOut;
	ImageBase imIn;
	imIn.load(cNomImgLue);

	//ImageBase imG(imIn.getWidth(), imIn.getHeight(), imIn.getColor());

	if(info == 'C')
	{
		for(int x = 0; x < imIn.getHeight(); ++x)
		{
			printf("%d %d\n", x, imIn[x][indice]);
		}
	}
	else if(info == 'L')
	{
		for(int y = 0; y < imIn.getWidth(); ++y)
		{
			printf("%d %d\n", y, imIn[indice][y]);
		}
	}
	else
	{
		printf("Usage: ImageIn.pgm C(ou L) Indice \n"); 
		return 1;
	}

	return 0;
}
예제 #20
0
	void LoadSmiley(void)
	{
		if (m_img != NULL) return;

		m_img = m_sml->CreateCachedImage();
		if (m_img && m_img->IsAnimated() && opt.AnimateDlg) {
			m_nFramePosition = 0;
			m_img->SelectFrame(m_nFramePosition);
			long frtm = m_img->GetFrameDelay();
			m_counter = frtm / 10 + ((frtm % 10) >= 5);

			regAniSmileys.insert(this);
			if (timerId == 0) {
				timerId = 0xffffffff;
				CallFunctionAsync(sttMainThreadCallback, NULL);
			}
		}
		else m_nFramePosition = m_sml->GetStaticFrame();
	}
예제 #21
0
int main(int argc, char* argv[]) {
  
  if (argc != 4) {
    printf("Usage: ImageIn.pgm ImageOut.pgm Degre \n"); 
    return 1;
  }
   
  int degre = atoi(argv[3]);
  
  imIn.load(argv[1]);
  imOut1.load(argv[1]);
  imOut2.load(argv[1]);

  dilatation(degre,NULL);
  erosion(degre,argv[2]);

  return 0;

}
예제 #22
0
cl::NDRange VectorProgram::GetRange(EProgramVersions Version, const ImageBase& Img1)
{
   switch (Version)
   {
   case Fast:
      // The fast version uses a 1D range
      return cl::NDRange(Img1.Width() * Img1.Height() * Img1.NbChannels() / GetVectorWidth(Img1.DataType()), 1, 1);

   case Standard:
   case Unaligned:
      // The other versions use a 2D range
      return Img1.VectorRange(GetVectorWidth(Img1.DataType()));

   case NbVersions:
   default:
      throw cl::Error(CL_INVALID_PROGRAM, "Invalid program version in VectorProgram");
   }

}
예제 #23
0
ImageBase* AddCacheImage(const CMString& file, int index)
{
	CMString tmpfile(file); tmpfile.AppendFormat(_T("#%d"), index);
	unsigned id = mir_hash(tmpfile.c_str(), tmpfile.GetLength() * sizeof(TCHAR));

	WaitForSingleObject(g_hMutexIm, 3000);

	ImageBase srch(id);
	ImageBase *img = g_imagecache.find(&srch);
	if (img == NULL) {
		int ind = file.ReverseFind('.');
		if (ind == -1)
			return NULL;

		CMString ext = file.Mid(ind+1);
		ext.MakeLower();
		if (ext == _T("dll") || ext == _T("exe"))
			img = opt.HQScaling ? (ImageBase*)new ImageType(id, file, index, icoDll) : (ImageBase*)new IconType(id, file, index, icoDll);
		else if (ext == _T("ico"))
			img = opt.HQScaling ? (ImageBase*)new ImageType(id, file, 0, icoFile) : (ImageBase*)new IconType(id, file, 0, icoFile);
		else if (ext == _T("icl"))
			img = opt.HQScaling ? (ImageBase*)new ImageType(id, file, index, icoIcl) : (ImageBase*)new IconType(id, file, index, icoIcl);
		else if (ext == _T("gif"))
			img = new ImageType(id, file, NULL);
		else if (fei == NULL || ext == _T("tif") || ext == _T("tiff"))
			img = new ImageType(id, file, NULL);
		else
			img = opt.HQScaling ? (ImageBase*)new ImageType(id, file, NULL) : (ImageBase*)new ImageFType(id, file);

		g_imagecache.insert(img);

		if (timerId == 0) {
			timerId = 0xffffffff;
			CallFunctionAsync(sttMainThreadCallback, NULL);
		}
	}
	else img->AddRef();

	ReleaseMutex(g_hMutexIm);

	return img;
}
예제 #24
0
	void UnloadSmiley(void)
	{
		regAniSmileys.remove(this);

		if (timerId && (timerId+1) && regAniSmileys.getCount() == 0) {
			KillTimer(NULL, timerId);
			timerId = 0;
		}
		if (m_img) m_img->Release();
		m_img = NULL;
	}
예제 #25
0
파일: histo.cpp 프로젝트: Arihy/TPM
int main(int argc, char **argv)
{
	///////////////////////////////////////// Exemple d'un seuillage d'image
	char cNomImgLue[250];
  
	if(argc != 2) 
	{
		printf("Usage: ImageIn.pgm\n"); 
		return 1;
	}
	sscanf (argv[1],"%s",cNomImgLue);

	
	//ImageBase imIn, imOut;
	ImageBase imIn;
	imIn.load(cNomImgLue);

	//ImageBase imG(imIn.getWidth(), imIn.getHeight(), imIn.getColor());

	for(int i = 0; i < 256; ++i)
	{
		int occurence = 0;
		for(int x = 0; x < imIn.getHeight(); ++x)
		{
			for(int y = 0; y < imIn.getWidth(); ++y)
			{
				//seuillage 2 partie
				/*
				if (imIn[x][y] < S) 
					imOut[x][y] = 0;
				else imOut[x][y] = 255;
				*/
				if(imIn[x][y] == i)
					occurence++;
			}
		}
		printf("%d %d\n", i, occurence);
	}

	return 0;
}
예제 #26
0
bool VectorProgram::IsImageFlush(const ImageBase& Source)
{
   if (Source.Width() * Source.NbChannels() * Source.DepthBytes() != Source.Step())
      return false;  // Image has padding

   if ((Source.Width() * Source.NbChannels()) % GetVectorWidth(Source.DataType()) != 0)
      return false;  // width is not a multiple of VectorWidth

   return true;
}
예제 #27
0
int main(int argc, char **argv) {
	char cNomImgLue[250], cNomImgEcrite[250];
  
	if (argc < 3) 
	{
		printf("Usage: ImageIn.pgm ImageOut.pgm\n"); 
		return 1;
	}
	sscanf (argv[1],"%s",cNomImgLue) ;
	sscanf (argv[2],"%s",cNomImgEcrite);
	
	
	//ImageBase imIn, imOut;
	ImageBase imIn;
	imIn.load(cNomImgLue);

	ImageBase imOut(imIn.getWidth(), imIn.getHeight(), imIn.getColor());

	unsigned char Vmin = 0, Vmax = 0, S;
	for(int x = 0; x < imIn.getHeight(); ++x)
		for(int y = 0; y < imIn.getWidth(); ++y)
		{
		  Vmin = min(Vmin,imIn[x][y]);
		  Vmax = max(Vmax,imIn[x][y]);
		}
	S = (Vmax + Vmin)/2;
	
	for(int x = 0; x < imIn.getHeight(); ++x)
		for(int y = 0; y < imIn.getWidth(); ++y)
		{
			if (imIn[x][y] < S) imOut[x][y] = 0;
			else imOut[x][y] = 255;
		}
		
	imOut.save(cNomImgEcrite);
	
	printf("Niveau maximum : %d\nNiveau minimum : %d\nSeuil : %d\n",Vmax,Vmin,S); 

	return 0;
}
예제 #28
0
void DisplayImpl::clippedDrawImage(Point p, Point a, Point b,
        const ImageBase& img)
{
    //Qt backend is meant to catch errors, so be bastard
    if(a.x()<0 || a.y()<0 || b.x()<0 || b.y()<0)
        throw(logic_error("DisplayImpl::clippedDrawImage:"
                " negative value in point"));
    if(a.x()>=width || a.y()>=height || b.x()>=width || b.y()>=height)
        throw(logic_error("DisplayImpl::clippedDrawImage:"
                " point outside display bounds"));
    if(a.x()>b.x() || a.y()>b.y())
        throw(logic_error("DisplayImpl::clippedDrawImage: reversed points"));

    img.clippedDraw(*this,p,a,b);
    beginPixelCalled=false;
}
예제 #29
0
int main(int argc, char **argv)
{
	///////////////////////////////////////// Exemple d'un seuillage d'image
	char cNomImgLue[250], cNomImgEcrite[250];
	int S1, S2, S3, S4;
  
	if (argc < 6 || argc > 7) 
	{
		printf("Usage: ImageIn.pgm ImageOut.pgm Seuil_1 Seuil_2 Seuil_3 [Seuil_4] \n"); 
		return 1;
	}
	sscanf (argv[1],"%s",cNomImgLue) ;
	sscanf (argv[2],"%s",cNomImgEcrite);
	sscanf (argv[3],"%d",&S1);
	sscanf (argv[4],"%d",&S2);
	sscanf (argv[5],"%d",&S3);
	if(argc == 7){sscanf (argv[6],"%d",&S4);}
	
	
	//ImageBase imIn, imOut;
	ImageBase imIn;
	imIn.load(cNomImgLue);

	//ImageBase imG(imIn.getWidth(), imIn.getHeight(), imIn.getColor());
	ImageBase imOut(imIn.getWidth(), imIn.getHeight(), imIn.getColor());

	if(argc == 6){
		for(int x = 0; x < imIn.getHeight(); ++x){
			for(int y = 0; y < imIn.getWidth(); ++y)
			{
				if (imIn[x][y] < S1) 
					imOut[x][y] = 0;
				else if (imIn[x][y] < S2)
					imOut[x][y] = 85;
				else if (imIn[x][y] < S3)
					imOut[x][y] = 170;
				else imOut[x][y] = 255;
			}
		}
	}else{
		for(int x = 0; x < imIn.getHeight(); ++x){
			for(int y = 0; y < imIn.getWidth(); ++y)
			{
				if (imIn[x][y] < S1) 
					imOut[x][y] = 0;
				else if (imIn[x][y] < S2)
					imOut[x][y] = 64;
				else if (imIn[x][y] < S3)
					imOut[x][y] = 128;
				else if (imIn[x][y] < S4)
					imOut[x][y] = 192;
				else imOut[x][y] = 255;
			}
		}
	}

	imOut.save(cNomImgEcrite);
		

	
	
	///////////////////////////////////////// Exemple de création d'une image couleur
	ImageBase imC(50, 100, true);

	for(int y = 0; y < imC.getHeight(); ++y)
		for(int x = 0; x < imC.getWidth(); ++x)
		{
			imC[y*3][x*3+0] = 200; // R
			imC[y*3][x*3+1] = 0; // G
			imC[y*3][x*3+2] = 0; // B
		}
		
	imC.save("imC.ppm");
		



	///////////////////////////////////////// Exemple de création d'une image en niveau de gris
	ImageBase imG(50, 100, false);

	for(int y = 0; y < imG.getHeight(); ++y)
		for(int x = 0; x < imG.getWidth(); ++x)
			imG[y][x] = 50;

	imG.save("imG.pgm");




	ImageBase imC2, imG2;
	
	///////////////////////////////////////// Exemple lecture image couleur
	imC2.load("imC.ppm");
	///////////////////////////////////////// Exemple lecture image en niveau de gris
	imG2.load("imG.pgm");
	
	

	///////////////////////////////////////// Exemple de récupération d'un plan de l'image
	ImageBase *R = imC2.getPlan(ImageBase::PLAN_R);
	R->save("R.pgm");
	delete R;
	


	return 0;
}
예제 #30
0
void dilatation(int degre, char* outname) {

  int w = imIn.getWidth(), h = imIn.getHeight();
	
  for(int x=0;x<w;x++) {
    for(int y=0; y<h;y++) {
      if(!imIn.getColor()) {

        //Image en niveaux de gris
  
        bool change = true;

        for(int i=-degre;i<=degre;i++) {
          for(int j=-degre;j<=degre;j++) {
            if( y+j >= degre && y+j < h-degre && x+i >= degre && x+i < w-degre && imIn[y+j][x+i] < imIn[y][x] ) {
              imOut1[y][x] = imIn[y+j][x+i];
              change = false;
            }
          }
        }

        if(change) {
          imOut1[y][x] = imIn[y][x];
        }

      }

      else {

        //Image en couleur RGB

        bool changeR = true, changeG = true, changeB = true;

        for(int i=-degre;i<=degre;i++) {
          for(int j=-degre;j<=degre;j++) {
            if(y+j >= degre && y+j < h-degre && x+i >= degre && x+i < w-degre) {
              if(imIn[3*(y+j)][3*(x+i)] < imIn[3*y][3*x]) {
                imOut1[3*y][3*x] = imIn[3*(y+j)][3*(x+i)];
                changeR = false;
              }
              if(imIn[3*(y+j)][3*(x+i)+1] < imIn[3*y][3*x+1]) {
                imOut1[3*y][3*x+1] = imIn[3*(y+j)][3*(x+i)+1];
                changeG = false;
              }
              if(imIn[3*(y+j)][3*(x+i)+2] < imIn[3*y][3*x+2]) {
                imOut1[3*y][3*x+2] = imIn[3*(y+j)][3*(x+i)+2];
                changeB = false;
              }
            }
          }
        }

        if(changeR) {
          imOut1[3*y][3*x] = imIn[3*y][3*x];
        }
        if(changeG) {
          imOut1[3*y][3*x+1] = imIn[3*y][3*x+1];
        }
        if(changeB) {
          imOut1[3*y][3*x+2] = imIn[3*y][3*x+2];
        }
      }
    }
  }

  if(outname != NULL) imOut1.save(outname);
}