我完成了获得灰度值,但我不知道如何使用函数将灰度转换为二进制图像.请帮帮我,这里是我的功能代码:
public Bitmap toBinary(Bitmap bmpOriginal) {
int width, height, threshold;
height = bmpOriginal.getHeight();
width = bmpOriginal.getWidth();
threshold = 127;
final Bitmap bmpBinary = null;
for(int x = 0; x < width; ++x) {
for(int y = 0; y < height; ++y) {
// get one pixel color
int pixel = bmpOriginal.getPixel(x, y);
//get grayscale value
int gray = (int)(pixel & 0xFF);
//get binary value
if(gray < threshold){
bmpBinary.setPixel(x, y, 0);
} else{
bmpBinary.setPixel(x, y, 255);
}
}
}
return bmpBinary; …Run Code Online (Sandbox Code Playgroud) 我必须编写一个程序,将强度图像转换为黑白图像.我只是想我可以从原始矩阵中获取一个值,如果它高于平均值,则使另一个数组中的相应单元格等于1,否则等于零:
for x=1:X
for y=1:Y
if I(x,y)>mean(I(:))
bw(x,y)=1;
elseif I(x,y)<mean(I(:))
bw(x,y)=0;
end
end
end
image(bw)
Run Code Online (Sandbox Code Playgroud)
不幸的是,我得到的图像都是黑色的.为什么?
我在uint8,顺便说一下.2-Lena.tiff图像
#include<stdio.h>
void main(){
int i;
i = 011;
printf("%d",i);
}
Run Code Online (Sandbox Code Playgroud)
该程序输出为9.我不知道原因.请帮我弄清楚为什么这个程序提供这个输出.
这个表叫'临时'
No. of times Clear Included Percentage
2 1 1 0.50
4 0 1 0.60
0 0 0 0.20
Run Code Online (Sandbox Code Playgroud)
例如,如果我有这个数据集,我想要转换'No.下的0以上的所有数字.时间'列到1并且保持0原样.
总的来说,我想要一个看起来像这样的数据集
No. of times Clear Included Percentage
1 1 1 0.50
1 0 1 0.60
0 0 0 0.20
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我有一个e从0开始的整数升序列表,我希望有一个二进制列表,b其中i-th元素为1,当且仅当i属于e.
例如,如果e=[0,1,3,6],那么这个二进制列表应该是[1,1,0,1,0,0,1],其中第一个1是因为0在e,第二个1是因为1在e,第三个0是因为2不在e,依此类推.
你可以在下面找到我的代码.
我的问题是: python中是否内置了一些内容?如果没有,我的方法是最有效的吗?
def list2bin(e):
b=[1]
j=1
for i in range(1, e[-1]+1):
if i==e[j]:
b.append(1)
j+=1
else:
b.append(0)
return(b)
Run Code Online (Sandbox Code Playgroud) 如果我将两个16位数相乘,结果将是32位长.但为什么会这样呢?这有什么明确的解释?
并且为了正确理解:对此的计算是:n位数乘以m位数给出(n + m)位数?

例如,对于8位数.我为什么要放弃这个?我明白溢出只是当我在同一个符号中添加2个数字并在另一个符号中得到结果时.这是什么情况?
所以我已经构建了我的程序但是我一遍又一遍地说同样的错误:
benchmark.f90(17): error #6451: A dummy argument name is required in this context. [N]
INTEGER, intent (in) :: N
------------------------^
benchmark.f90(18): error #6420: This array name is invalid in this context. [A]
REAL, intent (out), DIMENSION (N), allocatable :: a
--------------------------------------------------^
benchmark.f90(18): error #6646: ALLOCATABLE or POINTER attribute dictates a deferred-shape-array [A]
REAL, intent (out), DIMENSION (N), allocatable :: a
--------------------------------------------------^
benchmark.f90(17): error #6219: This variable, used in a specification expression, must be a dummy argument, a COMMON block object, …Run Code Online (Sandbox Code Playgroud) decimal = input("Please insert a number: ")
if decimal > 256:
print "Value too big!"
elif decimal < 1:
print "Value too small!"
else:
decimal % 2
binary1 = []
binary0 = []
if decimal % 2 == 0:
binary1.append[decimal]
else:
binary0.append[decimal]
print binary1
print binary0
Run Code Online (Sandbox Code Playgroud)
到目前为止,我想测试这段代码,它在第13行说:
TypeError:builtin_function_or_method'对象没有属性
__getitem__.
我不明白为什么这是错的.
我想将十进制数转换为二进制数.我只想尝试获取输入的第一个值然后将其存储在列表中以便使用,然后将其作为0或1添加到另一个列表中.如果输入不等于2,则添加一个零.我该怎么做?