Search Results

Search found 1575 results on 63 pages for 'pixel'.

Page 2/63 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Comparing bitmap data in AS3 pixel for pixel

    - by Jono
    Hi, I am looking for a fairly simple image comparison method in AS3. I have taken an image from a web cam (with no subject) passed it in to bitmap data, then a second image is taken (this time with a subject) to compare this data, from these two images I would like to create a mask from the pixels that match on both bitmaps. I have been scratching my head for a while, and I am not really making any progress. Could any one point me in the right direction for pixel comparison method, something like getPixel32() Cheers Jono

    Read the article

  • AS3: How to access pixel data efficiently?

    - by JonoRR
    I'm working a game. The game requires entities to analyse an image and head towards pixels with specific properties (high red channel, etc.) I've looked into Pixel Bender, but this only seems useful for writing new colors to the image. At the moment, even at a low resolution (200x200) just one entity scanning the image slows to 1-2 Frames/second. I'm embedding the image and instance it as a Bitmap as a child of the stage. The 1-2 FPS situation is using BitmapData.getPixel() (on each pixel) with a distance calculation beforehand. I'm wondering if there's any way I can do this more efficiently... My first thought was some sort of spatial partioning coupled with splitting the image up into many smaller pieces. I also feel like Pixel Bender should be able to help somehow, however I've had little experience with it. Cheers for any help. Jonathan

    Read the article

  • How to create an ARGB_8888 pixel value?

    - by vidstige
    Say I want to create an array of pixel values to pass into the createBitmap method described here. I have three int values r, g, b in the range 0 - 0xff. How do I transform those into a opaque pixel p? Does the alpha channel go in the high byte or the low byte? I googled up the documentation but it only states that: Each pixel is stored on 4 bytes. Each channel (RGB and alpha for translucency) is stored with 8 bits of precision (256 possible values.) This configuration is very flexible and offers the best quality. It should be used whenever possible. So, how to write this method? int createPixel(int r, int g, int b) { retrurn ? }

    Read the article

  • In HLSL pixel shader , why is SV_POSITION different to other semantics?

    - by tina nyaa
    In my HLSL pixel shader, SV_POSITION seems to have different values to any other semantic I use. I don't understand why this is. Can you please explain it? For example, I am using a triangle with the following coordinates: (0.0f, 0.5f) (0.5f, -0.5f) (-0.5f, -0.5f) The w and z values are 0 and 1, respectively. This is the pixel shader. struct VS_IN { float4 pos : POSITION; }; struct PS_IN { float4 pos : SV_POSITION; float4 k : LOLIMASEMANTIC; }; PS_IN VS( VS_IN input ) { PS_IN output = (PS_IN)0; output.pos = input.pos; output.k = input.pos; return output; } float4 PS( PS_IN input ) : SV_Target { // screenshot 1 return input.pos; // screenshot 2 return input.k; } technique10 Render { pass P0 { SetGeometryShader( 0 ); SetVertexShader( CompileShader( vs_4_0, VS() ) ); SetPixelShader( CompileShader( ps_4_0, PS() ) ); } } Screenshot 1: http://i.stack.imgur.com/rutGU.png Screenshot 2: http://i.stack.imgur.com/NStug.png (Sorry, I'm not allowed to post images until I have a lot of 'reputation') When I use the first statement (result is first screenshot), the one that uses the SV_POSITION semantic, the result is completely unexpected and is yellow, whereas using any other semantic will produce the expected result. Why is this?

    Read the article

  • Computing pixel's screen position in a vertex shader: right or wrong?

    - by cubrman
    I am building a deferred rendering engine and I have a question. The article I took the sample code from suggested computing screen position of the pixel as follows: VertexShaderFunction() { ... output.Position = mul(worldViewProj, input.Position); output.ScreenPosition = output.Position; } PixelShaderFunction() { input.ScreenPosition.xy /= input.ScreenPosition.w; float2 TexCoord = 0.5f * (float2(input.ScreenPosition.x,-input.ScreenPosition.y) + 1); ... } The question is what if I compute the position in the vertex shader (which should optimize the performance as VSF is launched significantly less number of times than PSF) would I get the per-vertex lighting insted. Here is how I want to do this: VertexShaderFunction() { ... output.Position = mul(worldViewProj, input.Position); output.ScreenPosition.xy = output.Position / output.Position.w; } PixelShaderFunction() { float2 TexCoord = 0.5f * (float2(input.ScreenPosition.x,-input.ScreenPosition.y) + 1); ... } What exactly happens with the data I pass from VS to PS? How exactly is it interpolated? Will it give me the right per-pixel result in this case? I tried launching the game both ways and saw no visual difference. Is my assumption right? Thanks. P.S. I am optimizing the point light shader, so I actually pass a sphere geometry into the VS.

    Read the article

  • How to get skin tone color pixel in iPhone?

    - by aman-gupta
    Hi In my application I m using following way to get red pixel in a image // // PixelsAccessAppDelegate.h // PixelsAccess // // Created by Fortune1 on 14/04/10. // Copyright MyCompanyName 2010. All rights reserved. // import @class clsPixelAccess; NSUInteger numberOfRedPixels; NSUInteger numberOfRedPixels1; NSUInteger numberOfRedPixels2; NSUInteger numberOfRedPixels3; NSUInteger numberOfRedPixels4; NSUInteger numberOfRedPixels5; NSUInteger numberOfRedPixels6; NSUInteger numberOfRedPixels7; NSUInteger numberOfRedPixels8; NSUInteger numberOfRedPixels9; NSUInteger numberOfRedPixels10; NSUInteger numberOfRedPixels11; NSUInteger numberOfRedPixels12; NSUInteger numberOfRedPixels13; NSUInteger numberOfRedPixels14; NSUInteger numberOfRedPixels15; NSUInteger numberOfRedPixels16; NSUInteger numberOfRedPixels17; NSUInteger numberOfRedPixels18; NSUInteger numberOfRedPixels19; NSUInteger numberOfRedPixels20; NSUInteger numberOfRedPixels21; NSUInteger numberOfRedPixels22; NSUInteger numberOfRedPixels23; NSUInteger numberOfRedPixels24; NSUInteger numberOfRedPixels25; NSUInteger numberOfRedPixels26; NSUInteger numberOfRedPixels27; NSUInteger numberOfRedPixels28; NSUInteger numberOfRedPixels29; NSUInteger numberOfRedPixels30; NSUInteger numberOfRedPixels31; @interface PixelsAccessAppDelegate : NSObject { UIWindow *window; clsPixelAccess *obj; } @property (nonatomic, retain) IBOutlet UIWindow *window; -(IBAction)processImage:(id)sender; @end //////////////////// // // PixelsAccessAppDelegate.m // PixelsAccess // // Created by Fortune1 on 14/04/10. // Copyright MyCompanyName 2010. All rights reserved. // import "PixelsAccessAppDelegate.h" import "clsPixelAccess.h" @implementation PixelsAccessAppDelegate @synthesize window; (IBAction)processImage:(id)sender { NSUInteger retVal; obj = [[clsPixelAccess alloc] init]; NSInteger imageSend =[obj processImage1:[UIImage imageNamed:@"s.jpg"]]; NSInteger iamgeCall =[obj getPixelData:retVal]; NSUInteger *numberOfRedPixels = retVal; //lblPixelCount.text = [NSString stringWithFormat: @"There are %d red pixels in the image", numberOfRedPixels]; } (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after application launch [window makeKeyAndVisible]; } (void)dealloc { [window release]; [super dealloc]; } @end /////////////// // // clsPixelsAccess.h // PixelsAccess // // Created by Fortune1 on 14/04/10. // Copyright 2010 MyCompanyName. All rights reserved. // import @interface clsPixelAccess : NSObject { } -(NSInteger) processImage1: (UIImage*) image; -(NSInteger)getPixelData:(NSUInteger *)pixelCount; @end ///////// // // clsPixelsAccess.m // PixelsAccess // // Created by Fortune1 on 14/04/10. // Copyright 2010 MyCompanyName. All rights reserved. // import "clsPixelAccess.h" import "PixelsAccessAppDelegate.h" @implementation clsPixelAccess struct pixel { //unsigned char r, g, b,a; Byte r, g, b, a; int count; }; -(NSInteger)getPixelData:(NSUInteger *)pixelCount { *pixelCount =numberOfRedPixels; return 1; } // Process the image and return the number of pure red pixels in it. (NSInteger) processImage1: (UIImage*) image { // Allocate a buffer big enough to hold all the pixels struct pixel* pixels = (struct pixel*) calloc(1, image.size.width * image.size.height * sizeof(struct pixel)); if (pixels != nil) { // Create a new bitmap CGContextRef context = CGBitmapContextCreate( (void*) pixels, image.size.width, image.size.height, 8, image.size.width * 4, CGImageGetColorSpace(image.CGImage), kCGImageAlphaPremultipliedLast ); //NSLog(@"1=%d, 2=%d, 3=%d", CGImageGetBitsPerComponent(image), CGImageGetBitsPerPixel(image),CGImageGetBytesPerRow(image)); if (context != NULL) { // Draw the image in the bitmap CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, image.size.width, image.size.height), image.CGImage); NSUInteger numberOfPixels = image.size.width * image.size.height; NSMutableArray *numberOfPixelsArray = [[[NSMutableArray alloc] initWithCapacity:numberOfPixelsArray] autorelease]; NSLog( @"Pixel data %d", numberOfPixelsArray); /* NSMatrix *newMatrix = [[NSMatrix alloc] initWithFrame:NSMakeRect(138.0f, 85.0f, 0.0f, 0.0f) mode:NSRadioModeMatrix prototype:prototypeButtonCell numberOfRows: numberOfColumns:]; */ while (numberOfPixels &gt; 0) { if (pixels-&gt;r &gt; 0 &amp;&amp; pixels-&gt;r &lt;= 7) { numberOfRedPixels++; } NSLog( @"Red pixel data %d",numberOfRedPixels); if (pixels-&gt;r &gt;= 8 &amp;&amp; pixels-&gt;r &lt;= 15) { numberOfRedPixels1++; } NSLog( @"Red pixel data1 %d",numberOfRedPixels1); if (pixels-&gt;r &gt;= 16 &amp;&amp; pixels-&gt;r &lt;=23 ) { numberOfRedPixels2++; } NSLog( @"Red pixel data2 %d",numberOfRedPixels2); if (pixels-&gt;r &gt;= 24 &amp;&amp; pixels-&gt;r &lt;=31 ) { numberOfRedPixels3++; } NSLog( @"Red pixel data3 %d",numberOfRedPixels3); if (pixels-&gt;r &gt;= 32 &amp;&amp; pixels-&gt;r &lt;= 39) { numberOfRedPixels4++; } NSLog( @"Red pixel data4 %d",numberOfRedPixels4); if (pixels-&gt;r &gt;= 40 &amp;&amp; pixels-&gt;r &lt;= 47) { numberOfRedPixels5++; } NSLog( @"Red pixel data5 %d",numberOfRedPixels5); if (pixels-&gt;r &gt;= 48 &amp;&amp; pixels-&gt;r &lt;= 55) { numberOfRedPixels6++; } NSLog( @"Red pixel data6 %d",numberOfRedPixels6); if(pixels-&gt;r &gt;= 56 &amp;&amp; pixels-&gt;r &lt;= 63) { numberOfRedPixels7++; } NSLog( @"Red pixel data7 %d",numberOfRedPixels7); if (pixels-&gt;r &gt;= 64 &amp;&amp; pixels-&gt;r &lt;= 71) { numberOfRedPixels8++; } NSLog( @"Red pixel data8 %d",numberOfRedPixels8); if (pixels-&gt;r &gt;= 72 &amp;&amp; pixels-&gt;r &lt;= 79) { numberOfRedPixels9++; } NSLog( @"Red pixel data9 %d",numberOfRedPixels9); if (pixels-&gt;r &gt;= 80 &amp;&amp; pixels-&gt;r &lt;= 87) { numberOfRedPixels10++; } NSLog( @"Red pixel data10 %d",numberOfRedPixels10); if (pixels-&gt;r &gt;= 88 &amp;&amp; pixels-&gt;r &lt;= 95) { numberOfRedPixels11++; } NSLog( @"Red pixel data11 %d",numberOfRedPixels11); if (pixels-&gt;r &gt;= 96 &amp;&amp; pixels-&gt;r &lt;= 103) { numberOfRedPixels12++; } NSLog( @"Red pixel data12 %d",numberOfRedPixels12); if (pixels-&gt;r &gt;= 104 &amp;&amp; pixels-&gt;r &lt;= 111) { numberOfRedPixels13++; } NSLog( @"Red pixel data13 %d",numberOfRedPixels13); if (pixels-&gt;r &gt;= 112 &amp;&amp; pixels-&gt;r &lt;= 119) { numberOfRedPixels14++; } NSLog( @"Red pixel data14 %d",numberOfRedPixels14); if (pixels-&gt;r &gt;= 120 &amp;&amp; pixels-&gt;r &lt;= 127) { numberOfRedPixels15++; } NSLog( @"Red pixel data15 %d",numberOfRedPixels15); if (pixels-&gt;r &gt; 128 &amp;&amp; pixels-&gt;r &lt;= 135) { numberOfRedPixels16++; } NSLog( @"Red pixel data16 %d",numberOfRedPixels16); if (pixels-&gt;r &gt;= 136 &amp;&amp; pixels-&gt;r &lt;= 143) { numberOfRedPixels17++; } NSLog( @"Red pixel data17 %d",numberOfRedPixels17); if (pixels-&gt;r &gt;= 144 &amp;&amp; pixels-&gt;r &lt;=151) { numberOfRedPixels18++; } NSLog( @"Red pixel data18 %d",numberOfRedPixels18); if (pixels-&gt;r &gt;= 152 &amp;&amp; pixels-&gt;r &lt;=159 ) { numberOfRedPixels19++; } NSLog( @"Red pixel data19 %d",numberOfRedPixels19); if (pixels-&gt;r &gt;= 160 &amp;&amp; pixels-&gt;r &lt;= 167) { numberOfRedPixels20++; } NSLog( @"Red pixel data20 %d",numberOfRedPixels20); if (pixels-&gt;r &gt;= 168 &amp;&amp; pixels-&gt;r &lt;= 175) { numberOfRedPixels21++; } NSLog( @"Red pixel data21 %d",numberOfRedPixels21); if (pixels-&gt;r &gt;= 176 &amp;&amp; pixels-&gt;r &lt;= 199) { numberOfRedPixels22++; } NSLog( @"Red pixel data22 %d",numberOfRedPixels22); if(pixels-&gt;r &gt;= 184 &amp;&amp; pixels-&gt;r &lt;= 191) { numberOfRedPixels23++; } NSLog( @"Red pixel data23 %d",numberOfRedPixels23); if (pixels-&gt;r &gt;= 192 &amp;&amp; pixels-&gt;r &lt;= 199) { numberOfRedPixels24++; } NSLog( @"Red pixel data24 %d",numberOfRedPixels24); if (pixels-&gt;r &gt;= 200 &amp;&amp; pixels-&gt;r &lt;= 207) { numberOfRedPixels25++; } NSLog( @"Red pixel data25 %d",numberOfRedPixels25); if (pixels-&gt;r &gt;= 208 &amp;&amp; pixels-&gt;r &lt;= 215) { numberOfRedPixels26++; } NSLog( @"Red pixel data26 %d",numberOfRedPixels26); if (pixels-&gt;r &gt;= 216 &amp;&amp; pixels-&gt;r &lt;= 223) { numberOfRedPixels27++; } NSLog( @"Red pixel data27 %d",numberOfRedPixels27); if (pixels-&gt;r &gt;= 224 &amp;&amp; pixels-&gt;r &lt;= 231) { numberOfRedPixels28++; } NSLog( @"Red pixel data28 %d",numberOfRedPixels28); if (pixels-&gt;r &gt;= 232 &amp;&amp; pixels-&gt;r &lt;= 239) { numberOfRedPixels29++; } NSLog( @"Red pixel data29 %d",numberOfRedPixels29); if (pixels-&gt;r &gt;= 240 &amp;&amp; pixels-&gt;r &lt;= 247) { numberOfRedPixels30++; } NSLog( @"Red pixel data30 %d",numberOfRedPixels30); if (pixels-&gt;r &gt;= 248) { numberOfRedPixels31++; } NSLog( @"Red pixel data31 %d",numberOfRedPixels31); pixels++; numberOfPixels--; } CGContextRelease(context); } free(pixels); } return 1; } @end My problem is I want skin Tone Pixel how it could be possible Please help me out. Thanks in Advance

    Read the article

  • Pixel bender shaders with multiple outputs in flash?

    - by sold
    According to the pixel bender specs a shader can have one or more outputs. The pixel bender toolkit, whose "export to flash" option tends to be preety strict about the flash specific do's and dont's, would even compile such a shader without complaints. However actionscript's shader related classes seem to be geared toward single output shaders. Is there any way to have multiple shader outputs in flash?

    Read the article

  • Pixel Shader Giving Black output

    - by Yashwinder
    I am coding in C# using Windows Forms and the SlimDX API to show the effect of a pixel shader. When I am setting the pixel shader, I am getting a black output screen but if I am not using the pixel shader then I am getting my image rendered on the screen. I have the following C# code using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.Runtime.InteropServices; using SlimDX.Direct3D9; using SlimDX; using SlimDX.Windows; using System.Drawing; using System.Threading; namespace WindowsFormsApplication1 { // Vertex structure. [StructLayout(LayoutKind.Sequential)] struct Vertex { public Vector3 Position; public float Tu; public float Tv; public static int SizeBytes { get { return Marshal.SizeOf(typeof(Vertex)); } } public static VertexFormat Format { get { return VertexFormat.Position | VertexFormat.Texture1; } } } static class Program { public static Device D3DDevice; // Direct3D device. public static VertexBuffer Vertices; // Vertex buffer object used to hold vertices. public static Texture Image; // Texture object to hold the image loaded from a file. public static int time; // Used for rotation caculations. public static float angle; // Angle of rottaion. public static Form1 Window =new Form1(); public static string filepath; static VertexShader vertexShader = null; static ConstantTable constantTable = null; static ImageInformation info; [STAThread] static void Main() { filepath = "C:\\Users\\Public\\Pictures\\Sample Pictures\\Garden.jpg"; info = new ImageInformation(); info = ImageInformation.FromFile(filepath); PresentParameters presentParams = new PresentParameters(); // Below are the required bare mininum, needed to initialize the D3D device. presentParams.BackBufferHeight = info.Height; // BackBufferHeight, set to the Window's height. presentParams.BackBufferWidth = info.Width+200; // BackBufferWidth, set to the Window's width. presentParams.Windowed =true; presentParams.DeviceWindowHandle = Window.panel2 .Handle; // DeviceWindowHandle, set to the Window's handle. // Create the device. D3DDevice = new Device(new Direct3D (), 0, DeviceType.Hardware, Window.Handle, CreateFlags.HardwareVertexProcessing, presentParams); // Create the vertex buffer and fill with the triangle vertices. (Non-indexed) // Remember 3 vetices for a triangle, 2 tris per quad = 6. Vertices = new VertexBuffer(D3DDevice, 6 * Vertex.SizeBytes, Usage.WriteOnly, VertexFormat.None, Pool.Managed); DataStream stream = Vertices.Lock(0, 0, LockFlags.None); stream.WriteRange(BuildVertexData()); Vertices.Unlock(); // Create the texture. Image = Texture.FromFile(D3DDevice,filepath ); // Turn off culling, so we see the front and back of the triangle D3DDevice.SetRenderState(RenderState.CullMode, Cull.None); // Turn off lighting D3DDevice.SetRenderState(RenderState.Lighting, false); ShaderBytecode sbcv = ShaderBytecode.CompileFromFile("C:\\Users\\yashwinder singh\\Desktop\\vertexShader.vs", "vs_main", "vs_1_1", ShaderFlags.None); constantTable = sbcv.ConstantTable; vertexShader = new VertexShader(D3DDevice, sbcv); ShaderBytecode sbc = ShaderBytecode.CompileFromFile("C:\\Users\\yashwinder singh\\Desktop\\pixelShader.txt", "ps_main", "ps_3_0", ShaderFlags.None); PixelShader ps = new PixelShader(D3DDevice, sbc); VertexDeclaration vertexDecl = new VertexDeclaration(D3DDevice, new[] { new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.PositionTransformed, 0), new VertexElement(0, 12, DeclarationType.Float2 , DeclarationMethod.Default, DeclarationUsage.TextureCoordinate , 0), VertexElement.VertexDeclarationEnd }); Application.EnableVisualStyles(); MessagePump.Run(Window, () => { // Clear the backbuffer to a black color. D3DDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); // Begin the scene. D3DDevice.BeginScene(); // Setup the world, view and projection matrices. //D3DDevice.VertexShader = vertexShader; //D3DDevice.PixelShader = ps; // Render the vertex buffer. D3DDevice.SetStreamSource(0, Vertices, 0, Vertex.SizeBytes); D3DDevice.VertexFormat = Vertex.Format; // Setup our texture. Using Textures introduces the texture stage states, // which govern how Textures get blended together (in the case of multiple // Textures) and lighting information. D3DDevice.SetTexture(0, Image); // Now drawing 2 triangles, for a quad. D3DDevice.DrawPrimitives(PrimitiveType.TriangleList , 0, 2); // End the scene. D3DDevice.EndScene(); // Present the backbuffer contents to the screen. D3DDevice.Present(); }); if (Image != null) Image.Dispose(); if (Vertices != null) Vertices.Dispose(); if (D3DDevice != null) D3DDevice.Dispose(); } private static Vertex[] BuildVertexData() { Vertex[] vertexData = new Vertex[6]; vertexData[0].Position = new Vector3(-1.0f, 1.0f, 0.0f); vertexData[0].Tu = 0.0f; vertexData[0].Tv = 0.0f; vertexData[1].Position = new Vector3(-1.0f, -1.0f, 0.0f); vertexData[1].Tu = 0.0f; vertexData[1].Tv = 1.0f; vertexData[2].Position = new Vector3(1.0f, 1.0f, 0.0f); vertexData[2].Tu = 1.0f; vertexData[2].Tv = 0.0f; vertexData[3].Position = new Vector3(-1.0f, -1.0f, 0.0f); vertexData[3].Tu = 0.0f; vertexData[3].Tv = 1.0f; vertexData[4].Position = new Vector3(1.0f, -1.0f, 0.0f); vertexData[4].Tu = 1.0f; vertexData[4].Tv = 1.0f; vertexData[5].Position = new Vector3(1.0f, 1.0f, 0.0f); vertexData[5].Tu = 1.0f; vertexData[5].Tv = 0.0f; return vertexData; } } } And my pixel shader and vertex shader code are as following // Pixel shader input structure struct PS_INPUT { float4 Position : POSITION; float2 Texture : TEXCOORD0; }; // Pixel shader output structure struct PS_OUTPUT { float4 Color : COLOR0; }; // Global variables sampler2D Tex0; // Name: Simple Pixel Shader // Type: Pixel shader // Desc: Fetch texture and blend with constant color // PS_OUTPUT ps_main( in PS_INPUT In ) { PS_OUTPUT Out; //create an output pixel Out.Color = tex2D(Tex0, In.Texture); //do a texture lookup Out.Color *= float4(0.9f, 0.8f, 0.0f, 1); //do a simple effect return Out; //return output pixel } // Vertex shader input structure struct VS_INPUT { float4 Position : POSITION; float2 Texture : TEXCOORD0; }; // Vertex shader output structure struct VS_OUTPUT { float4 Position : POSITION; float2 Texture : TEXCOORD0; }; // Global variables float4x4 WorldViewProj; // Name: Simple Vertex Shader // Type: Vertex shader // Desc: Vertex transformation and texture coord pass-through // VS_OUTPUT vs_main( in VS_INPUT In ) { VS_OUTPUT Out; //create an output vertex Out.Position = mul(In.Position, WorldViewProj); //apply vertex transformation Out.Texture = In.Texture; //copy original texcoords return Out; //return output vertex }

    Read the article

  • Image/"most resembling pixel" search optimization?

    - by SigTerm
    The situation: Let's say I have an image A, say, 512x512 pixels, and image B, 5x5 or 7x7 pixels. Both images are 24bit rgb, and B have 1bit alpha mask (so each pixel is either completely transparent or completely solid). I need to find within image A a pixel which (with its' neighbors) most closely resembles image B, OR the pixel that probably most closely resembles image B. Resemblance is calculated as "distance" which is sum of "distances" between non-transparent B's pixels and A's pixels divided by number of non-transparent B's pixels. Here is a sample SDL code for explanation: struct Pixel{ unsigned char b, g, r, a; }; void fillPixel(int x, int y, SDL_Surface* dst, SDL_Surface* src, int dstMaskX, int dstMaskY){ Pixel& dstPix = *((Pixel*)((char*)(dst->pixels) + sizeof(Pixel)*x + dst->pitch*y)); int xMin = x + texWidth - searchWidth; int xMax = xMin + searchWidth*2; int yMin = y + texHeight - searchHeight; int yMax = yMin + searchHeight*2; int numFilled = 0; for (int curY = yMin; curY < yMax; curY++) for (int curX = xMin; curX < xMax; curX++){ Pixel& cur = *((Pixel*)((char*)(dst->pixels) + sizeof(Pixel)*(curX & texMaskX) + dst->pitch*(curY & texMaskY))); if (cur.a != 0) numFilled++; } if (numFilled == 0){ int srcX = rand() % src->w; int srcY = rand() % src->h; dstPix = *((Pixel*)((char*)(src->pixels) + sizeof(Pixel)*srcX + src->pitch*srcY)); dstPix.a = 0xFF; return; } int storedSrcX = rand() % src->w; int storedSrcY = rand() % src->h; float lastDifference = 3.40282347e+37F; //unsigned char mask = for (int srcY = searchHeight; srcY < (src->h - searchHeight); srcY++) for (int srcX = searchWidth; srcX < (src->w - searchWidth); srcX++){ float curDifference = 0; int numPixels = 0; for (int tmpY = -searchHeight; tmpY < searchHeight; tmpY++) for(int tmpX = -searchWidth; tmpX < searchWidth; tmpX++){ Pixel& tmpSrc = *((Pixel*)((char*)(src->pixels) + sizeof(Pixel)*(srcX+tmpX) + src->pitch*(srcY+tmpY))); Pixel& tmpDst = *((Pixel*)((char*)(dst->pixels) + sizeof(Pixel)*((x + dst->w + tmpX) & dstMaskX) + dst->pitch*((y + dst->h + tmpY) & dstMaskY))); if (tmpDst.a){ numPixels++; int dr = tmpSrc.r - tmpDst.r; int dg = tmpSrc.g - tmpDst.g; int db = tmpSrc.g - tmpDst.g; curDifference += dr*dr + dg*dg + db*db; } } if (numPixels) curDifference /= (float)numPixels; if (curDifference < lastDifference){ lastDifference = curDifference; storedSrcX = srcX; storedSrcY = srcY; } } dstPix = *((Pixel*)((char*)(src->pixels) + sizeof(Pixel)*storedSrcX + src->pitch*storedSrcY)); dstPix.a = 0xFF; } This thing is supposed to be used for texture generation. Now, the question: The easiest way to do this is brute force search (which is used in example routine). But it is slow - even using GPU acceleration and dual core cpu won't make it much faster. It looks like I can't use modified binary search because of B's mask. So, how can I find desired pixel faster? Additional Info: It is allowed to use 2 cores, GPU acceleration, CUDA, and 1.5..2 gigabytes of RAM for the task. I would prefer to avoid some kind of lengthy preprocessing phase that will take 30 minutes to finish. Ideas?

    Read the article

  • C# GDI - How to check if a Pixel is opaque or not?

    - by rkawano
    I am using a method to get a pixel of the image to check if this point is transparent or not. I am using GetPixel that returns a System.Drawing.Color with a 32bit color info. This struct have the "A" property where I can get the alpha value of pixel, according to this MSDN topic. Code: using (Bitmap bmp = new Bitmap(path)) { Color pixel = bmp.GetPixel(0, 0); if (pixel.A == 0) // This is a fully transparent pixel else // This is not a fully transparent pixel } When I use this method with a fully transparent PNG images it returns 0. When I run with a white semi-transparent images, it will give me other values starting on 1 and up to 86, where 86 are given for images with a 100% alfa (full opaque). But with opaque JPEG images, the "A" property are giving me all sort of values like 56, 71, 86, 129, and others, depending on image. But these pixels are fully opaques! How are the correct way to check if a pixel is opaque or not?

    Read the article

  • Pixel Shader Effect Examples

    - by Chris Nicol
    I've seen a number of pixel-shader effect examples, stuff like swirl on an image. But I'm wondering if anyone knows of any examples or tutorials for more practical uses of shader effects? I'm not saying that a swirl effect doesn't have it's uses, it's just that many of the examples I've found have the basic effect explained and don't go into how it might be used subtly with another effect or transition to produce a wonderful effect. There's a video here, that outlines all the WPF Effects Library, but I'm not sure how I would use some of them in a practical context. For example, when Flash 8 came out with effects like blur, I found a wonderful video that showed how to use the blur effect to create a cool effect with speeding text, that video inspired many ideas of what I could do with the effects in Flash 8. I'm looking for something similar with Pixel Shader Effects.

    Read the article

  • Access to a single pixel in C#

    - by Malki
    Hello, I'm working on a school project right now. It's meant to be a 3D editing software, (like a very minimized version of Maya). I have to write it in C#, using the 'Windows Application Project'. I intend to implement all the 3D stuff myself, from projections to shading. My question is, how can I get direct access to a single pixel in the C# windows application? I know I'm going to have a main view port in the window. But I haven't decided yet how it will be made. Is there a built in object that I can use, that will let me define the boundaries of the view port, and then paint each pixel individually? (I'm just shooting in the dark here, I don't know much about C#. I mostly program in C) Thanks, Malki.

    Read the article

  • per pixel based collision detection.

    - by pengume
    I was wondering if anyone had any ideas on how to get per pixel collision detection for the android. I saw that the andEngine has great collision detection on rotation as well but couldn't see where the actual detection happened per pixel. Also noticed a couple solutions for java, could these be replicated for use with the Android SDK? Maybe someone here has a clean piece of code I could look at to help understand what is going on with per pixel detection and also why when rotating it is a different process.

    Read the article

  • GDL Presents: Women Techmakers with Pixel Qi

    GDL Presents: Women Techmakers with Pixel Qi Jean Wang sits down with 2011 Anita Borg "Woman of Vision" Award for Innovation winner Mary Lou Jepsen of Pixel Qi to discuss overcoming technical challenges in hardware, drawing on Mary Lou's experience leading the engineering and architectural design of the $100 laptops that inspired the One Laptop Per Child (OLPC) organization. Hosts: Jean Wang - Lead Hardware Engineer for Project Glass | Vivian Cromwell - Manager, Global Chrome Developer Relations Guest: Mary Lou Jepsen - CEO and Founder, Pixel Qi From: GoogleDevelopers Views: 0 0 ratings Time: 01:00:00 More in Science & Technology

    Read the article

  • OpenGL 2D Rasterization Sub-Pixel Translations

    - by Armin Ronacher
    I have a tile based 2D engine where the projection matrix is an orthographic view of the world without any scaling applied. Thus: one pixel texture is drawn on the screen in the same size. That all works well and looks nice but if the camera makes a sub-pixel movement small lines appear between the tiles. I can tell you in advance what does not fix the problem: GL_NEAREST texture interpolation GL_CLAMP_TO_EDGE What does “fix” the problem is anchoring the camera to the nearest pixel instead of doing a sub-pixel translation. I can live with that, but the camera movement becomes jerky. Any ideas how to fix that problem without resorting to the rounding trick I do currently?

    Read the article

  • In 3D camera math, calculate what Z depth is pixel unity for a given FOV

    - by badweasel
    I am working in iOS and OpenGL ES 2.0. Through trial and error I've figured out a frustum to where at a specific z depth pixels drawn are 1 to 1 with my source textures. So 1 pixel in my texture is 1 pixel on the screen. For 2d games this is good. Of course it means that I also factor in things like the size of the quad and the size of the texture. For example if my sprite is a quad 32x32 pixels. The quad size is 3.2 units wide and tall. And the texcoords are 32 / the size of the texture wide and tall. Then the frustum is: matrixFrustum(-(float)backingWidth/frustumScale,(float)backingWidth/frustumScale, -(float)backingHeight/frustumScale, (float)backingHeight/frustumScale, 40, 1000, mProjection); Where frustumScale is 800 for a retina screen. Then at a distance of 800 from camera the sprite is pixel for pixel the same as photoshop. For 3d games sometimes I still want to be able to do this. But depending on the scene I sometimes need the FOV to be different things. I'm looking for a way to figure out what Z depth will achieve this same pixel unity for a given FOV. For this my mProjection is set using: matrixPerspective(cameraFOV, near, far, (float)backingWidth / (float)backingHeight, mProjection); With testing I found that at an FOV of 45.0 a Z of 38.5 is very close to pixel unity. And at an FOV of 30.0 a Z of 59.5 is about right. But how can I calculate a value that is spot on? Here's my matrixPerspecitve code: void matrixPerspective(float angle, float near, float far, float aspect, mat4 m) { //float size = near * tanf(angle / 360.0 * M_PI); float size = near * tanf(degreesToRadians(angle) / 2.0); float left = -size, right = size, bottom = -size / aspect, top = size / aspect; // Unused values in perspective formula. m[1] = m[2] = m[3] = m[4] = 0; m[6] = m[7] = m[12] = m[13] = m[15] = 0; // Perspective formula. m[0] = 2 * near / (right - left); m[5] = 2 * near / (top - bottom); m[8] = (right + left) / (right - left); m[9] = (top + bottom) / (top - bottom); m[10] = -(far + near) / (far - near); m[11] = -1; m[14] = -(2 * far * near) / (far - near); } And my mView is set using: lookAtMatrix(cameraPos, camLookAt, camUpVector, mView); * UPDATE * I'm going to leave this here in case anyone has a different solution, can explain how they do it, or why this works. This is what I figured out. In my system I use a 10th scale unit to pixels on non-retina displays and a 20th scale on retina displays. The iPhone is 640 pixels wide on retina and 320 pixels wide on non-retina (obsolete). So if I want something to be the full screen width I divide by 20 to get the OpenGL unit width. Then divide that by 2 to get the left and right unit position. Something 32 units wide centered on the screen goes from -16 to +16. Believe it or not I have an excel spreadsheet do all this math for me and output all the vertex data for my sprite sheet. It's an arbitrary thing I made up to do .1 units = 1 non-retina pixel or 2 retina pixels. I could have made it .01 units = 2 pixels and someday I might switch to that. But for now it's the other. So the width of the screen in units is 32.0, and that means the left most pixel is at -16.0 and the right most is at 16.0. After messing a bit I figured out that if I take the [0] value of an identity modelViewProjection matrix and multiply it by 16 I get the depth required to get 1:1 pixels. I don't know why. I don't know if the 16 is related to the screen size or just a lucky guess. But I did a test where I placed a sprite at that calculated depth and varied the FOV through all the valid values and the object stays steady on screen with 1:1 pixels. So now I'm just calculating the unityDepth that way. If someone gives me a better answer I'll checkmark it.

    Read the article

  • Pretty Pixel-level Picture Painting, Programatically

    - by dreeves
    My mac laptop has 1,024,000 pixels. What's the simplest way to turn my display completely black and go nuts with writing little programs to twiddle pixels to my heart's delight? To make it more concrete, say I wanted to implement the Chaos Game to draw a Sierpinski triangle, at the pixel level, with nothing else on the screen. What are ways to do that?

    Read the article

  • How to set Alpha value from pixel shader in SlimDX Direct3d9

    - by Yashwinder
    I am trying to set alpha value of color as color.a = 0.5f in my pixel shader but all the time it is giving an exception. I can set color.r, color.g, color.b but it is not allowing me to set color.a and throwing an exception D3DERR_INVALIDCALL: Invalid call (-2005530516). I have just created a direct3d9 device and assigned my pixel shader to it. My pixel shader code is as below sampler2D ourImage : register(s0); float4 main(float2 locationInSource : TEXCOORD) : COLOR { float4 color = tex2D( ourImage , locationInSource.xy); color.a = 0.2; return color; } I am creating my pixel shader as byte[] byteCode = GiveFxFile(transitionEffect.PixelShaderFileName); var shaderBytecode = ShaderBytecode.Compile(byteCode, "main", "ps_2_0", ShaderFlags.None); var pixelShader = new PixelShader(device, ShaderBytecode); _device.PixelShader=pixelShader; I have initialized my device as var _presentParams = new PresentParameters { Windowed = _isWindowedMode, BackBufferWidth = (int)SystemParameters.PrimaryScreenWidth, BackBufferHeight = (int)SystemParameters.PrimaryScreenHeight, // Enable Z-Buffer // This is not really needed in this sample but real applications generaly use it EnableAutoDepthStencil = true, AutoDepthStencilFormat = Format.D16, // How to swap backbuffer in front and how many per screen refresh BackBufferCount = 1, SwapEffect = SwapEffect.Copy, BackBufferFormat = _direct3D.Adapters[0].CurrentDisplayMode.Format, PresentationInterval = PresentInterval.Immediate, DeviceWindowHandle = _windowHandle }; _device = new Device(_direct3D, 0, DeviceType.Hardware, _windowHandle, deviceFlags | CreateFlags.Multithreaded, _presentParams);

    Read the article

  • How to Fix a Stuck Pixel on an LCD Monitor

    - by Chris Hoffman
    Have you ever noticed that a pixel – a little dot on your computer’s LCD monitor – is staying a single color all of the time? You have a stuck pixel. Luckily, stuck pixels aren’t always permanent. Stuck and dead pixels are hardware problems. They’re often caused by manufacturing flaws – pixels aren’t supposed to get stuck or die over time. Image Credit: Alexi Kostibas on Flickr How to Fix a Stuck Pixel on an LCD Monitor How to Factory Reset Your Android Phone or Tablet When It Won’t Boot Our Geek Trivia App for Windows 8 is Now Available Everywhere

    Read the article

  • perl: tk: a way/widget that allows pixel level control over the output

    - by chhh
    I want something like a canvas, but where i'd be able to manipulate pixels easily in addition to all the provided geometries, that can be drawn on canvas. Is it possible to embed something like GD::Image into a canvas? So then I maybe could make the image transparent and set some pixels in it (GD::Image-setPixel()) positioning it over the canvas? ps: well, that doesn't necessarily have to be perl, as there seem to be bindings for all the libs for most scripting (and not only) languages.

    Read the article

  • Pixel Perfect Collision Detection in Cocos2dx

    - by Happybirthday
    I am trying to port the pixel perfect collision detection in Cocos2d-x the original version was made for Cocos2D and can be found here: http://www.cocos2d-iphone.org/forums/topic/pixel-perfect-collision-detection-using-color-blending/ Here is my code for the Cocos2d-x version bool CollisionDetection::areTheSpritesColliding(cocos2d::CCSprite *spr1, cocos2d::CCSprite *spr2, bool pp, CCRenderTexture* _rt) { bool isColliding = false; CCRect intersection; CCRect r1 = spr1-boundingBox(); CCRect r2 = spr2-boundingBox(); intersection = CCRectMake(fmax(r1.getMinX(),r2.getMinX()), fmax( r1.getMinY(), r2.getMinY()) ,0,0); intersection.size.width = fmin(r1.getMaxX(), r2.getMaxX() - intersection.getMinX()); intersection.size.height = fmin(r1.getMaxY(), r2.getMaxY() - intersection.getMinY()); // Look for simple bounding box collision if ( (intersection.size.width0) && (intersection.size.height0) ) { // If we're not checking for pixel perfect collisions, return true if (!pp) { return true; } unsigned int x = intersection.origin.x; unsigned int y = intersection.origin.y; unsigned int w = intersection.size.width; unsigned int h = intersection.size.height; unsigned int numPixels = w * h; //CCLog("Intersection X and Y %d, %d", x, y); //CCLog("Number of pixels %d", numPixels); // Draw into the RenderTexture _rt-beginWithClear( 0, 0, 0, 0); // Render both sprites: first one in RED and second one in GREEN glColorMask(1, 0, 0, 1); spr1-visit(); glColorMask(0, 1, 0, 1); spr2-visit(); glColorMask(1, 1, 1, 1); // Get color values of intersection area ccColor4B *buffer = (ccColor4B *)malloc( sizeof(ccColor4B) * numPixels ); glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, buffer); _rt-end(); // Read buffer unsigned int step = 1; for(unsigned int i=0; i 0 && color.g 0) { isColliding = true; break; } } // Free buffer memory free(buffer); } return isColliding; } My code is working perfectly if I send the "pp" parameter as false. That is if I do only a bounding box collision but I am not able to get it working correctly for the case when I need Pixel Perfect collision. I think the opengl masking code is not working as I intended. Here is the code for "_rt" _rt = CCRenderTexture::create(visibleSize.width, visibleSize.height); _rt-setPosition(ccp(origin.x + visibleSize.width * 0.5f, origin.y + visibleSize.height * 0.5f)); this-addChild(_rt, 1000000); _rt-setVisible(true); //For testing I think I am making a mistake with the implementation of this CCRenderTexture Can anyone guide me with what I am doing wrong ? Thank you for your time :)

    Read the article

  • Pixel tracking problem in PHP

    - by kash
    Let me first explain what i am trying to do: step 1 : domain-a.com - cookie is set using a redirecting PHP script(placed on domain-b.com) when a link to domain-b.com is clicked from this domain step 2 : domain-b.com-main website -after a certain browsing user reaches domain-c.com step 3 : domain-c.com - when user reaches the thankyou page I placed an img tag with src = PHP confirmation script. (which confirms the cookie-placed on domain-b.com) Everything is working like charm with Chrome and FF, but IE is not able detect or recognize the cookie inside the confirmation script on step-3. I am not able to find any specific reason for this. I will really appreciate if anyone can help on this.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >