iOS Development

ios – Drawing line overlays over edges of CIImage

I’ve a customized Steel CIKernel that shows edges on the picture in pink colour. Within the shader, I do a convolution to compute Sobel gradient after which return the colour as pink or authentic colour. However I imagine there ought to be a method to do the identical utilizing builtin CIFilters or MPS shaders. However how?

extern "C" half4 drawEdges (coreimage::sampler inputImage, 
                             coreimage::vacation spot dest)
 {
  float2 destCoord = dest.coord();
  float2 srcCoord = inputImage.coord();
  half4 colour =  half4(inputImage.pattern(srcCoord)); 

  float2 m11Coord = inputImage.remodel(destCoord + float2(-1.0,+1.0));

  half3 m11 = half3(inputImage.pattern(m11Coord).rgb);   

  float2 m12Coord = inputImage.remodel(destCoord + float2(0.0,+1.0));
  half3 m12 = half3(inputImage.pattern(m12Coord).rgb); 
  float2 m13Coord = inputImage.remodel(destCoord + float2(+1.0,+1.0));
  half3 m13 = half3(inputImage.pattern(m13Coord).rgb);  

  float2 m21Coord = inputImage.remodel(destCoord + float2(-1.0,0.0));
  half3 m21 = half3(inputImage.pattern(m21Coord).rgb); 

  float2 m23Coord = inputImage.remodel(destCoord + float2(+1.0,0.0));
  half3 m23 = half3(inputImage.pattern(m23Coord).rgb);

  float2 m31Coord = inputImage.remodel(destCoord + float2(-1.0,-1.0));
  half3 m31 = half3(inputImage.pattern(m31Coord).rgb);

  float2 m32Coord = inputImage.remodel(destCoord + float2(0.0,-1.0));
  half3 m32 = half3(inputImage.pattern(m32Coord).rgb); 

  float2 m33Coord = inputImage.remodel(destCoord + float2(+1.0,+1.0));
  half3 m33 = half3(inputImage.pattern(m33Coord).rgb);

  half3 m31m13 = m31 - m13;
  half3 m11m33 = m33 - m11;
  half3 m32m12 = m32 - m12;
  half3 m21m23 = m21 - m23;
  half3 H = m32m12 + m32m12 + m11m33 + m31m13;
  half3 V = m21m23 + m21m23 - m11m33 + m31m13;

  half3 sobel = sqrt(H*H+V*V);
  half sobelLength = size(sobel);

  if (sobelLength > 0.9) {
    half4 redColor = half4(0.5h, 0.h, 0.0, 1.0);
    colour = redColor;
 }

  return half4(colour);
}


    

Credit: www.ismmailgsm.com

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button