我的图像中某个值超过某个值的像素我想变成红色,而像素值低于某个值我想变成蓝色。
到目前为止,我可以通过使用阈值处理获得红色像素矩阵和蓝色像素矩阵,并使用按位运算符设置像素值:
cvtColor(displayImage, displayImage, COLOR_GRAY2BGR);
threshold(displayImage, highThresh, highThreshVal, 255, 0);
highThresh = highThresh & Scalar(0, 0, 255); // Turn it red
threshold(displayImage, lowThresh, lowThreshVal, 255, 1);
lowThresh = lowThresh & Scalar(255, 0, 0); // Turn it blue
displayImage = lowThresh + highThresh;
当我显示displayImage
时,我几乎看到了我想要的东西。这是一张图片,lowThreshVal
以下的所有像素都是蓝色,highThreshVal
以上的所有像素都是红色。但是,这些值之间的像素都设置为0.然而,我想显示用蓝色和红色图像覆盖的原始图像。我不知道该怎么做,或者我采取最好的方法。
我知道我无法添加图像,因为我想确保阈值以上的每个像素都是纯红色,而不是红色和原始图像的混合,这会产生粉红色像素而不是亮红色像素,打败了我正在努力建立的目标。但截至目前,我仍然不知所措。
答案 0 :(得分:0)
这很有用。
Sub CreateNewWordDoc()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim arr(12)
'Bearing numbers I need to search
arr(0) = "(249_L), 38,7 %"
arr(1) = "(248_R), 38,7 %"
arr(2) = "(249_M), 38,7 "
arr(3) = "(3560), 38,7 "
arr(4) = "(3550), 38,7 %"
arr(5) = "(349_), 38,7 %"
arr(6) = "(348_), 38,7 %"
arr(7) = "(451), 38,7 %"
arr(8) = "(450L), 38,7 %"
arr(9) = "(450R), 38,7 %"
arr(10) = "(151), 38,7 %"
arr(11) = "(150L), 38,7 %"
arr(12) = "(150R), 38,7 %"
range2 = 6
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
'location of my word document
Set wrdDoc = wrdApp.Documents.Open("E:\Siemens\FullFlexibleGearbox.docx")
wrdDoc.Activate
wrdApp.Selection.HomeKey Unit:=wdStory
'for loop to reach all bearing location
For i = 0 To 12
Cells.Find(What:=arr(i), After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(2, 0).Range("A1:G8").Select
Application.CutCopyMode = False
Selection.Copy
With wrdApp.Selection
With .Find
.ClearFormatting
.MatchWildcards = False
.MatchWholeWord = False
.Text = arr(i)
.Execute
End With
.MoveRight Unit:=wdCharacter, Count:=2
.MoveDown Unit:=wdLine, Count:=1
.MoveDown Unit:=wdLine, Count:=6, Extend:=wdExtend
.MoveLeft Unit:=wdCharacter, Count:=6, Extend:=wdExtend
.Paste
.HomeKey Unit:=wdStory
End With
Next
End Sub