I have a 100x100 B&W image stored in a df (100 rows and 100 columns). I then use imshow to display it.
I would like to switch this to a single color image. To do this, I believe I need to change every cell which now contains 1 value ‘x’, to a list that contains this initial value, plus 2 more zeros ‘[x,0,0]’. What is the best way to make this change in each cell in my df?
Thanks! I have a B&W image stored in a dfold as code values from 0-255, in rows and columns. Then I have a second (df2) with the same number of rows and columns, and the value in each cell in that df will determine the color of each pixel in a new colored version of the original B&W image. I was just trying to make a red image first just to get the hang of turning the cells which contain integers, to now contain 3 element lists. I succeeded. The trick was to make a new df an object, which then permitted me to switch each cell from an integer to a list. I used dfnew = dfold.astype(object). Then I operated on dfnew to switch each cell from “x” to “[x,0,0]”.
For the rest of this, it seems that I need to go through dfold, row by row, and column by column, deciding what color each cell will be and then making the switch from integer to list. For example, I am setting the color blue if the value in the cell for df2 is between 0-2, green if it is between 2-4, and red if it is between 4-6. Is there a faster way of doing this than iterating over rows and columns. Perhaps by making a mask?
Just to help understand, the values in df2 are a sort of error magnitude. We are using color to show where we have the most errors in our B&W images.