Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use cut and (new) edge fades to white
#1
Say, for example, I have a layer that is solid red (255,0,0) on the left side and solid blue (0,0,255) on the right.  Then I cut out and keep a rectangle or polygon from the middle.  If I zoom in I see that the edge of the polygon fades to white.  The left fades from red to white, and the right from blue to white.

The original pixels, at what now is the edge, were full red (or blue).

Is there a way to cut that leaves the pixels at the edge at their original color (hue/sat/lum)?

This is what I did:
  pdb.gimp_image_select_polygon(image01, CHANNEL_OP_ADD, len(polygonPoints), polygonPoints)
  pdb.gimp_selection_invert(image01)
  pdb.gimp_edit_cut(layerobj)
  pdb.gimp_selection_invert(image01)

I think that what is happening is that for the cut the pixels at the edge might be considered as, for example, 80% inside the polygon and 20% outside - so they are given acolor that is 80% red.

I there way to select a threshold so that the pixels that are >= 50% red would be solid (255,0,0) red, otherwize they would be cut from the polygon?

Thanks,
Saurabh
Reply
#2
You can always use gimp-selection-sharpen() (which is the same as the Select>Sharpen menu). But IMHO your are misunderstanding something. The pixels on the edge of the polygon are partially transparent, but their RGB value is identical to the RGB values of the pixel in the polygon. The intermediate colors are due to this partial opacity blending with whatever is in the background. Normally you want to keep this partial opacity, this is what produces the smooth edges.
Reply
#3
Thanks for helping me with concepts / phrasing-this-correctly.

If you want to skip reading a bit of detail you can jump to the bottom of this post and start reading at  "*** My goal is ***"

I'll add some more detail, and explain it differently, here are the steps:

 - Have an image01 and a layer01, say 1000 x 1000 pixels
 - I draw on layer01
 - Copy layer01 to layer02 using pdb.gimp_layer_copy()
 - Note: Now both layer01 and layer02 are 'exactly' the same
 - Use these functions on layer02
       pdb.gimp_image_select_polygon()
       pdb.gimp_selection_invert()
       pdb.gimp_edit_cut()
       pdb.gimp_selection_invert()
   to cut away and keep a polygon in the cener of layer02, say 900 x 900 pixels

At this point, if layer02 is above layer01, and I am viewing 'both' layers.  The view that I want is as if I am viewing 'only' layer01.

This does work  (why would it not?)

So, at this point, there are no issues with  'intermediate colors (that) are due to this partial opacity blending with whatever is in the background'.   

Here is the problem:
I use pdb.gimp_hue_saturation() with appropriate arguments to make a given layer darker than the one above.  This part 'making layers darker' does work.  The thing is I see more than just one layer being darker than the one above.  I see a lighter border around the layer,  and this border is lighter than the layer,  and lighter than the layer below.   So it is like I have a light line draw around each layer.   This makes the transition from dark to light less subtle.

*** My goal is ***   
 - Render on a layer,  and do processing to make it look darker at the edges

*** Steps ***
 - Draw on one layer,  copy this layer to other layers
 - cut so that, from bottom to top, each layer is a smaller piece of the layer below  (no scaling is involved)
 - darken using pdb.gimp_hue_saturation(), so that from bottom to top layers go from being dark to light

Maybe there is a another way to do this,  but these steps give me good control of size and darkness.

All is ok except for the lighter lines that I see around each layer,   which makes the transition from dark to light less subtle.

I tried gimp-selection-sharpen(), it did not seem to help.

Saurabh
Reply
#4
Would you have a sample picture (you can attach XCF (file should be under 2MB) or even XCF.GZ (also 2MB but due to compression this is usually equivalent to a 6MB XCF).
Reply
#5
Here is the xcf.gz file   image_2.xcf.gz   This shows a part of the image that represents what I am talking about.    You have to zoom in to see it.


Attached Files
.gz   image_2.xcf.gz (Size: 740.17 KB / Downloads: 189)
Reply
#6
(03-01-2018, 01:36 AM)sbhairava72 Wrote: Here is the xcf.gz file   image_2.xcf.gz   This shows a part of the image that represents what I am talking about.    You have to zoom in to see it.

Was this file helpful?
Reply
#7
Yes, I'l looking into it. I can't really reproduce the problem, though. How to you cut the triangles exactly? Can you post the relevant Python code?.
Reply
#8
Is it ok if I post the code as a private message (PM)?
Reply
#9
Here is my code (attached).


Attached Files
.gz   gimp_0005_star.py.gz (Size: 6.06 KB / Downloads: 177)
Reply
#10
Think the culprit is here:
Code:
   pdb.gimp_image_select_polygon(image01, CHANNEL_OP_ADD, len(polygonPoints), polygonPoints)          #temp add this back
   pdb.gimp_selection_invert(image01)
   #~~~~~~~~~~
   layerobj = layerdata[i].layerobj        #-()
   pdb.gimp_edit_cut(layerobj)
   pdb.gimp_selection_invert(image01)

   #---  darken all but the top layer  -----------------------------
   if i != len(layerdata)-1:
     pdb.gimp_hue_saturation(layerobj, ALL_HUES, 0, layerdata[i].lumsadjust, layerdata[i].satadjust)

The polygon selections create partially selected pixels. This is normal. When you cut, these partially selected pixels become partially transparent and you get a smooth cut. However, you keep that selection. So when you apply the hue-saturation, the effect of the hue-saturation on these partially selected pixels isn't as strong as on the other (fully selected) pixels and since the goal of the hue-saturation operation is to darken things, these pixels remain lighter.

The fix would be to remove the selection before you apply the hue-saturation... AFAIK H/S only applies to the RGB channels and will leave the alpha channel unchanged.

Edit: another possible fix is to to the Hue-Saturation change before the cut...
Reply


Forum Jump: