I'm in the process of doing a histogram match for two images. So far, I've been able to do some statistics on the levels of grey, histogram the values, and in an external python script, determine new values per value of grey. i.e the reference value of 1 might be value 10 in the target image.
Can the Raster expression evaluator or another transformer conduct a test to read the the value of a pixel and reassign it a new value. For example if i'm looking at the red channel, IF pixelvalue == 1 ? pixelvalue = 20 : (IF pixelvalue == 2) ? pixelvalue = 30 etc etc...
Maybe this needs to involve pallettes?
Best answer by takashi
This data flow produced the same result as the previous one.
Did this help you find an answer to your question?
This post is closed to further activity.
It may be a question with a best answer, an implemented idea, or just a post needing no comment.
If you have a follow-up or related question, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.
In the past (maybe FME 2012 and earlier), the RasterExpressionEvaluator had only one field for entering expressions, and semicolons were used to separate multiple expressions for each band.
But the interface has been changed. Currently you have to enter expressions seperately for each row associated to a band, if your raster has multiple bands. When you used semicolons in an expression, such an error occurs.
I guess you are going to calculate a value for one band.
i.e.
If A[0] == 0 Then 3
Else If A[0] == 1 Then 4
Else If A[0] == 2 Then 5 ... and so on.
If my understanding is correct, you can use a nested "if" statement.
e.g.
@if (A[0] == 0, 3,
@if (A[0] == 1, 4,
@if (A[0] == 2, 5,
@if (A[0] == 3, 6,
@if (A[0] == 4, 7,
@if (A[0] == 5, 8,
@if (A[0] == 6, 9,
@if (A[0] == 7, 10,
@if (A[0] == 8, 11, 12)))))))))
However, the error says your expression is going to calculate values for 546 entries. It means that you have 546 conditions in fact.
Although it may be possible theoretically to write a nested "if" statement for such many conditions, it would be too complicated and also troublesome.
There could be more simple way. For example, if the requirement is to just add 3 to the original pixel value, this expression would be enough.
A[0] + 3
If you explain the requirement concretely, we could consider a workaround.
What i've tried was using an older raster expression evaluator that had the text box input for interpretations and was able to copy paste the correct number of matching interpretations to the expressions. i.e 546 interpretations, 546 evaluations.
The problem with that was, after processing every pixel contained 546 bands.
Just to describe what I have in further detail. The histogram matching has the source image and target image broken up into R,G,B and the percentage of occuring decimal values 0-255 across both images is calculated. Comparing these percentage values, I can determine, for example, when my target image has a Red8 value of 50, this is equivalent to source image Red8 30. So i've created a mapping of new RGB values for my target image. [30,50]
So with the mapping I need to change the target image's rgb values according to the new mapping
The array above represents the mapping of a red channel. The index of the array would describe the decimal value. For example, Decimal 0 should be 6 instead. Decimal 1 should be 7.
Summary, I need a way to map new rgb values to a raster and write the new raster image out.
I'm now considering converting image to point cloud, change the red green blue component of the points, and then rasterize the point cloud.
The older RasterExpressionEvaluator generates 546 bands if the expression has 546 entries which are separated with semicolons. Even if you use the old transformer, you have to set a nested "if" statement to map a band value.
I'm still unclear the mapping rule.
The array that you posted contains 182 elements. The requirement is to change a pixel value like this?
Ok, so the nested expression works but I've now hit some type of limit with how many nestings it can support. I've reach about 130 nests, but it will not do the full 182 let alone 546, it simple says "error running translation" . I can work around this by dividing the script into two per channel, but ultimately costs me time.
I've had a look for colormap but mostly lead to some of your own posts Gio. I need some pointers on the colourmap and what transformers I should be working with.
How do I reinsert a colourmap. Is this part of transforming into palettes instead of bands?
Firstly, create 3 pallete attributes with 256 entries for each band. Use "GRAY8" as the value interpretation for every pallete. These pallete attributes will be used as value mapping table for each band. See also the help doc of the RasterPaletteExtractor to learn about the format of pallete attribute.
e.g.
-----
GRAY8
0 6
1 7
2 8
3 9
4 10
...
254 ???
255 ???
-----
Divide the data flow into 3 streams and add these transformers seperately for each band.
(1) RasterSelector - select 2 bands
Band and Pallete List: 1;2 ("0;2" for green band, "0;1" for blue band)
(2) RasterBandRemover - remove selected bands. i.e. keep one band
(3) RasterSelector - select the first band
Band and Pallete List: 0
(4) RasterBandInterpretationCorercer
Destination Interpretation Type: UInt8
(5) RasterPaletteAdder
Palette Attribute: <specify the palette attribute for the band>
(6) RasterPaletteResolver
(7) RasterBandInterpretationCoercer - restore the original band interpretation
Destination Interpretation Type: Red8 ("Green8" for green band, "Blue8" for blue band)
(8) AttributeCreator
_order = 0 (1 for green band, 2 for blue band)
Send the 3 rasters to a Sorter to sort by "_order" ascending.
Finally, add a RasterBandCombiner to re-create an RGB raster.
The results from your workflow is amazing. The workbench with nested expressions method averages 5.5 minutes to compute whereas your workflow takes less than 30 seconds. That's a significant improvement will greatly reduce total processing time. Thank you very much.
We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.