Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
584 views
in Technique[技术] by (71.8m points)

matrix - Using getChannels() function in R pixmap package: I want black to be '1' and white to be '0', it is the inverse of this by default

I've imported a black and white pnm file with read.pnm(x). I have then used getChannels(x) to create matrix y. In this matrix, the black pixels are '0's, and the white pixels are '1's. I want the inverse of this, the black to be '1' and the white to be '0'. I know I can use a nested for loop to go through and correct all the values manually with val = 1 - val , but I was wondering if there is an easier way, or a function in R to 'reverse' or 'invert' a binary matrix like this without a nested for loop.

question from:https://stackoverflow.com/questions/66055426/using-getchannels-function-in-r-pixmap-package-i-want-black-to-be-1-and-whi

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...