<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[(Type mismatch??) Mein Sobel funktioniert nicht..]]></title><description><![CDATA[<p>Ich denke nicht, dass das Problem am Sobel selbst liegt, weshalb ich den Eintrag hier poste. Mein Problem ist wahrscheinlich eher das auseinanderhalten von Datentypen. Vielleicht sieht ja hier einer was.</p>
<pre><code class="language-cpp">#include &quot;SobelFilter.h&quot;

void SobelFilter::filterfunction (cImage *src, cImage *dest, int x, int y) {
	int maskx[] = {-1,0,1,-2,0,2,-1,0,1};
	int masky[] = {1,2,1,0,0,0,-1,-2,-1};

	int valx = 0;
	int valy = 0;
    // für jedes Filterelement
	for (int yd = -1; yd &lt;= 1; yd++) {
		for (int xd = -1; xd &lt;= 1; xd++) {
			unsigned  posx = xd + x;
			unsigned  posy = yd + y;
			// Wenn der Filter noch im Bild ist
			// zähle den Filterwert hinzu
			if (posx &gt;= 0 &amp;&amp; posy &gt;= 0 &amp;&amp; posx &lt; src-&gt;getWidth()
			 &amp;&amp; posy &lt; src-&gt;getHeight()) {
				valx += (int)src-&gt;getPixel(posx,posy,0) *  maskx[yd * 3 + xd]; 
				valy += (int)src-&gt;getPixel(posx,posy,0) *  masky[yd * 3 + xd];

			}
		}	
	}
                // was größer ist als 0xff (255), wird einfach entfernt.. 
		valx = abs(valx);
		valy = abs(valy);
		if (valx &gt; 0xff) valx = 0xff;
		if (valy &gt; 0xff) valy = 0xff;
		// die Richtung der Kante 
	     // int direction = (int)round(abs(atan ((float)valy / (float)valx )) * 2);
	    // Der Anstieg der Kante
		// int gradient = sqrt ((valx * valx) + (valy * valy)); 
		// Kurzform - etwas ungenauer aber schneller 
		// int gradient = (valy &gt; valx) ? valy : valx ;

		// Setzen der Farbwerte
		dest-&gt;setPixel(x, y, valx, 0);
		dest-&gt;setPixel(x, y, valx, 1);
		dest-&gt;setPixel(x, y, valx, 2);
}
</code></pre>
<p>Die filterfunction wird von einer Funktion aufgerufen, die das ganze Bild abläuft also &quot;foreach x ( foreach y (filterfunction)). Da ich noch andere Filter habe, ist das so ganz günstig, denk ich- ich implementiere immer nur die Filterfunktion neu.</p>
<p>Auf jeden Fall hier mein Problem:<br />
Ich hab das Beispielbild von <a href="http://www.generation5.org/content/2002/im01.asp" rel="nofollow">http://www.generation5.org/content/2002/im01.asp</a> genutzt und mein Ergebnis ist- naja, anders. Ich hab bei mir die 5 in schwarz auf dem bild und nix anders- schon garnicht die Ränder.</p>
<p>Meines Erachtens liegt hier ein Problem mit den Datentypen vor. Die Pixel sind breite * höhe * 3 Pixel (immer RGB) Ein Pixel ist ein unsigned char.</p>
<p>Kann mir wer helfen das Ganze zu bereinigen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/187787/type-mismatch-mein-sobel-funktioniert-nicht</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 20:24:19 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/187787.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 24 Jul 2007 07:31:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to (Type mismatch??) Mein Sobel funktioniert nicht.. on Tue, 24 Jul 2007 07:31:37 GMT]]></title><description><![CDATA[<p>Ich denke nicht, dass das Problem am Sobel selbst liegt, weshalb ich den Eintrag hier poste. Mein Problem ist wahrscheinlich eher das auseinanderhalten von Datentypen. Vielleicht sieht ja hier einer was.</p>
<pre><code class="language-cpp">#include &quot;SobelFilter.h&quot;

void SobelFilter::filterfunction (cImage *src, cImage *dest, int x, int y) {
	int maskx[] = {-1,0,1,-2,0,2,-1,0,1};
	int masky[] = {1,2,1,0,0,0,-1,-2,-1};

	int valx = 0;
	int valy = 0;
    // für jedes Filterelement
	for (int yd = -1; yd &lt;= 1; yd++) {
		for (int xd = -1; xd &lt;= 1; xd++) {
			unsigned  posx = xd + x;
			unsigned  posy = yd + y;
			// Wenn der Filter noch im Bild ist
			// zähle den Filterwert hinzu
			if (posx &gt;= 0 &amp;&amp; posy &gt;= 0 &amp;&amp; posx &lt; src-&gt;getWidth()
			 &amp;&amp; posy &lt; src-&gt;getHeight()) {
				valx += (int)src-&gt;getPixel(posx,posy,0) *  maskx[yd * 3 + xd]; 
				valy += (int)src-&gt;getPixel(posx,posy,0) *  masky[yd * 3 + xd];

			}
		}	
	}
                // was größer ist als 0xff (255), wird einfach entfernt.. 
		valx = abs(valx);
		valy = abs(valy);
		if (valx &gt; 0xff) valx = 0xff;
		if (valy &gt; 0xff) valy = 0xff;
		// die Richtung der Kante 
	     // int direction = (int)round(abs(atan ((float)valy / (float)valx )) * 2);
	    // Der Anstieg der Kante
		// int gradient = sqrt ((valx * valx) + (valy * valy)); 
		// Kurzform - etwas ungenauer aber schneller 
		// int gradient = (valy &gt; valx) ? valy : valx ;

		// Setzen der Farbwerte
		dest-&gt;setPixel(x, y, valx, 0);
		dest-&gt;setPixel(x, y, valx, 1);
		dest-&gt;setPixel(x, y, valx, 2);
}
</code></pre>
<p>Die filterfunction wird von einer Funktion aufgerufen, die das ganze Bild abläuft also &quot;foreach x ( foreach y (filterfunction)). Da ich noch andere Filter habe, ist das so ganz günstig, denk ich- ich implementiere immer nur die Filterfunktion neu.</p>
<p>Auf jeden Fall hier mein Problem:<br />
Ich hab das Beispielbild von <a href="http://www.generation5.org/content/2002/im01.asp" rel="nofollow">http://www.generation5.org/content/2002/im01.asp</a> genutzt und mein Ergebnis ist- naja, anders. Ich hab bei mir die 5 in schwarz auf dem bild und nix anders- schon garnicht die Ränder.</p>
<p>Meines Erachtens liegt hier ein Problem mit den Datentypen vor. Die Pixel sind breite * höhe * 3 Pixel (immer RGB) Ein Pixel ist ein unsigned char.</p>
<p>Kann mir wer helfen das Ganze zu bereinigen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1331269</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1331269</guid><dc:creator><![CDATA[DocJunioR]]></dc:creator><pubDate>Tue, 24 Jul 2007 07:31:37 GMT</pubDate></item><item><title><![CDATA[Reply to (Type mismatch??) Mein Sobel funktioniert nicht.. on Tue, 24 Jul 2007 07:41:54 GMT]]></title><description><![CDATA[<p>Wenn ich raten müsste, würde ich auf einen Index-Fehler bei deinen Mask-Arrays tippen. xd und yd laufen von -1 bis +1, also graifst du auf die Elemente zwischen -4 (3*-1 + -1) und +4 (3*+1 + +1) zu, die teilweise außerhalb des gültigen Index-Bereiches liegen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1331275</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1331275</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 24 Jul 2007 07:41:54 GMT</pubDate></item><item><title><![CDATA[Reply to (Type mismatch??) Mein Sobel funktioniert nicht.. on Tue, 24 Jul 2007 07:52:16 GMT]]></title><description><![CDATA[<p>manchmal bin ich auch zu blöd- warum zum Geier fällt mir sowas einfaches nicht auf?<br />
Jetzt tuts was es soll <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> danke.</p>
<p>P.S.: Man kann natürlich auch noch nen Schwellwert reinsetzen- falls es wer nutzen möchte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1331282</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1331282</guid><dc:creator><![CDATA[DocJunioR]]></dc:creator><pubDate>Tue, 24 Jul 2007 07:52:16 GMT</pubDate></item></channel></rss>