Question about blending 2 images together - python

I am looking at the sample code from the link below (Example 2: Italy Street Image with Wave Style).
https://github.com/dipanjanS/practical-machine-learning-with-python/blob/master/notebooks/Ch12_Deep_Learning_for_Computer_Vision/Neural%20Style%20Transfer%20Results%20-%20High%20Resolution.ipynb
Also, looking at input images from the link below.
https://github.com/dipanjanS/practical-machine-learning-with-python/tree/master/notebooks/Ch12_Deep_Learning_for_Computer_Vision/results/italy%20street
My question is this. Why is iteration_1.png to iteration_20.png being read into the code?
is_content_image = io.imread('results/italy street/italy_street.jpg')
is_style_image = io.imread('results/italy street/style1.png')
is_iter1 = io.imread('results/italy street/style_transfer_result_italy_street_gatys_at_iteration_1.png')
is_iter5 = io.imread('results/italy street/style_transfer_result_italy_street_gatys_at_iteration_5.png')
is_iter10 = io.imread('results/italy street/style_transfer_result_italy_street_gatys_at_iteration_10.png')
is_iter15 = io.imread('results/italy street/style_transfer_result_italy_street_gatys_at_iteration_15.png')
is_iter20 = io.imread('results/italy street/style_transfer_result_italy_street_gatys_at_iteration_20.png')
It seems like you would read in italy_street.jpg and style1.png, and the code should do the work of blending the images together, so after several iterations they are merged into a contamination of the two images. This seems intuitive, rather than doing 'io.imread' for several images, and then saving each image after each iteration. Am I missing something basic here? Or, is there a better demo other there, which shows how to blend two images together? Thanks for the look.

Related

Looking for a Python procedure to extract table information from image

We have paper invoices coming in, which are in paper format. We take images of these invoices, and wish to extract the information contained within the cells of the tabular region(s), and export them as CSV or similar.
The tables include multiple columns, and the cells contain numbers and words.
I have been searching around for ML-based Python procedures to have this performed, expecting this to be a relatively straightforward task (or maybe I'm mistaken), yet not much luck in coming across a procedure.
I can detect the horizontal and vertical lines, and combine them to locate the cells. But retrieving the information contained within the cells seems to be problematic.
Could I please get help?
I followed one procedure from this reference, yet came across an error with "bitnot":
import pytesseract
extract=[]
for i in range(len(order)):
for j in range(len(order[i])):
inside=''
if(len(order[i][j])==0):
extract.append(' ')
else:
for k in range(len(order[i][j])):
side1,side2,width,height = order[i][j][k][0],order[i][j][k][1], order[i][j][k][2],order[i][j][k][3]
final_extract = bitnot[side2:side2+h, side1:side1+width]
final_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (2, 1))
get_border = cv2.copyMakeBorder(final_extract,2,2,2,2, cv2.BORDER_CONSTANT,value=[255,255])
resize = cv2.resize(get_border, None, fx=2, fy=2, interpolation=cv2.INTER_CUBIC)
dil = cv2.dilate(resize, final_kernel,iterations=1)
ero = cv2.erode(dil, final_kernel,iterations=2)
ocr = pytesseract.image_to_string(ero)
if(len(ocr)==0):
ocr = pytesseract.image_to_string(ero, config='--psm 3')
inside = inside +" "+ ocr
extract.append(inside)
a = np.array(extract)
dataset = pd.DataFrame(a.reshape(len(hor), total))
dataset.to_excel("output1.xlsx")
The error I get is this:
final_extract = bitnot[side2:side2+h, side1:side1+width]
NameError: name 'bitnot' is not defined`

Is there any plot method in Python that can give me the plot in the image below? If not, could someone help in implementing it in R?

So in my project that is on football(soccer), what I want to find is how a title winning team goes on a winning run. For eg. 18 wins in a row that helped them to the title. So I want to show the trend/pattern of how they're winnning the consecutive games. So I have a csv file in which i have columns of W/D/L ( win/draw/loss) which consist of the data for this pattern. I'm doing my project using Python but the person who obtained the image using R of which I have no idea about. So if anyone could help me in obtaining this image in Python or R, it would be appreaciated.
The image has been attached below. Thanks for any help :).
WDL pattern of teams
Here's one way to do it in R using some made up data:
library(ggplot2)
#Some test data
set.seed(0)
testdata <- expand.grid(Team=c("Liverpool","Man U","Man City","Leicester", "Wolves"), Game=1:27)
testdata$Result <- sample(factor(c("Win","Draw","Loss"), levels=c("Win","Draw","Loss")), length(testdata[[1]]),
replace=TRUE, prob=c(0.4,0.2,0.4))
#plot
ggplot(testdata, aes(x=Game, y=as.numeric(Result), fill=Result)) + facet_grid(Team~., switch="y") +
geom_tile(colour="grey80", width=1,height=1) + scale_y_reverse(breaks=NULL) +
ylab("") + scale_fill_manual(values=c(Win="green3",Draw="Orange",Loss="Red"))
This results in the following plot:
If your data is not ordered with the teams in descending order, you'd need to convert testdata$Team to a factor ordered by the position in the league, see this question for example.

(hairSimulation/CFX) selecting multiple curves with its own duplicate and blendShape at the same time

In maya I am simulating hair and I want to lock the curves that are jittering. I duplicated those curves to make blend shapes, but there are too many to blend shape them individually. Is there a way to script to solve this? I think the way is to slice to get the name/number of the curves and blendShape all of them with a loop. But since I'm new to scripting I need help.
You can get follicles with this command :
fols = cmds.ls(type='follicle')
After that, find the curves simulated :
crvs = cmds.ls(fols, dag=True, type='nurbsCurve')
Loop through those curves and use :
dup = cmds.duplicate(c)[0] # where c is the iterator of the for loop on crvs
then :
bs = cmds.blendShape(dup, c)
You have few flags on every command but it should help you like name, weight and few more.
I don't have maya for few weeks so I hope it will help you
EDIT :
Not that follicle curves are set as intermediate, for blendshaping, you might need to temporarly set them :
cmds.setAttr(c+'.io', 0)
bs = cmds.blendShape(dup, c)
cmds.setAttr(c+'.io', 1)

Tesseract not picking up different colored text

I am trying to make a program that will scrape the text off of a screenshot using tesseract and python, and am having no issue getting one piece of it, however some text is lighter colored and is not being picked up by tesseract. Below is an example of a picture I am using:
I am am to get the text at the top of the picture, but not the 3 options below.
Here is the code I am using for grabbing the text
result = pytesseract.image_to_string(
screen, config="load_system_dawg=0 load_freq_dawg=0")
print("below is the total value scraped by the tesseract")
print(result)
# Split up newlines until we have our question and answers
parts = result.split("\n\n")
question = parts.pop(0).replace("\n", " ")
q_terms = question.split(" ")
q_terms = list(filter(lambda t: t not in stop, q_terms))
q_terms = set(q_terms)
parts = "\n".join(parts)
parts = parts.split("\n")
answers = list(filter(lambda p: len(p) > 0, parts))
I when I have plain text in black without a colored background I can get the answers array to be populated by the 3 below options, however not in this case. Is there any way I can go about fixing this?
You're missing binarization, or thresholding step.
In your case you can simply apply binary threshold on grayscale image.
Here is result image with threshold = 177
Here1 you can learn more about Thresholding with opencv python library

How to select geo when you have a component of that geo?

How do you get the name of a piece of geo when all you have is a component of that geo (uvs, faces, verts, edges)?
so for example I have:
MeshVertex(u'pCubeShape1.vtx[0]') #replace that with any of the following (uvs, faces, edges)
and what I would like to end up with is:
nt.Transform(u'pCube1')
How can I do this?
Say vtx = MeshVertex(u'pCubeShape1.vtx[0]')
then the transform/geo can be found using:
import pymel.core as pc
transforms = pc.listTransforms(vtx.node())
transform = transforms[0] #in case there is only one.
As your example, let's say v = MeshVertex(u'pCubeShape1.vtx[0]')
import pymel.core as pm
transform = v.node().getParent()
select(transform)
I know this question has already been answered, but I thought I'd post my way of doing this so that others can see different ways :)
Hope this helps

Categories