我知道在这里提出与黑客等级相关的问题是不合适的。但是这个简单的部分问题让我很难过,而且我开始怀疑我的图像处理概念。
他们给了一个图像
public void writeGatt(BluetoothDevice dev){
byte[] msgBuffer; //bluetooth send alway byte
String message = "1"; //ON
msgBuffer = message.getBytes();
mBtGatt = dev.connectGatt(this,false,GattCallback);//call Gattcallback
}
private final BluetoothGattCallback GattCallback = new BluetoothGattCallback() { //
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) {
intentAction = ACTION_GATT_CONNECTED;
broadcastUpdate(intentAction);
Log.i(TAG, "Connected to GATT server.");
Log.i(TAG, "Attempting to start service discovery:" +
mBtGatt.discoverServices());
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
intentAction = ACTION_GATT_DISCONNECTED;
broadcastUpdate(intentAction);
Log.i(TAG, "Disconnected from GATT server.");
}
}
@Override
// New services discovered
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED);
} else {
Log.w(TAG, "onServicesDiscovered received: " + status);
}
}
@Override
// Result of a characteristic read operation
public void onCharacteristicRead(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic,
int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
//broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
}
}
};
public void disconnect() { //deisconnect
if (mBtGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}
mBtGatt.close();
mBtGatt = null;
// mBluetoothGatt.close();
}
private void broadcastUpdate(final String action) {
final Intent intent = new Intent(action);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
Log.i("broadcastUpdate", "run broadcastUpdate send " + intent);
}
public void close() {
if (mBtGatt == null) {
return;
}
Log.w(TAG, "mBluetoothGatt closed");
;
mBtGatt.close();
mBtGatt = null;
}
public void writeRXCharacteristic(byte[] value)
{
/* BluetoothGattService RxService = mBtGatt.getService(RX_SERVICE_UUID);
//showMessage("mBluetoothGatt null"+ mBluetoothGatt);
if (RxService == null) {
//showMessage("Rx service not found!");
// broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
Log.i("RxService is null!!","RxService is null!!");
return;
}
BluetoothGattCharacteristic RxChar = RxService.getCharacteristic(RX_CHAR_UUID);
if (RxChar == null) {
// showMessage("Rx charateristic not found!");
//broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
Log.i("RxCHAR is null!!","RxCHAR is null!!");
return;
}
RxChar.setValue(value);
boolean status = mBtGatt.writeCharacteristic(RxChar);
Log.d(TAG, "write TXchar - status=" + status);*/
BluetoothGattService RxService=null;
while( RxService==null) {
try{
RxService = mBtGatt.getService(RX_SERVICE_UUID);}
catch(Exception e){
Log.d(TAG, e.toString());}
}
if (RxService == null) {
Log.d(TAG, "1");
return;
}BluetoothGattCharacteristic RxChar=null;
while( RxChar ==null){
try{
RxChar = RxService.getCharacteristic(RX_CHAR_UUID);}
catch(Exception e)
{Log.d(TAG, e.toString());}
}
if (RxChar == null) {
Log.d(TAG, "2");
return;
}
RxChar.setValue(value);
mBtGatt.writeCharacteristic(RxChar);
}
和结构元素
0 0 0 0
0 1 1 0
0 0 0 0
原点为左下角。
我得到了扩张的输出
1 0
1 1
(因为根据结构元素,我必须看到明亮的像素到原点的顶部和右侧)。我甚至用Matlab验证过。
但为什么黑客级别不接受我的输出?或者我错过了 二元图像膨胀的核心概念?
答案 0 :(得分:3)
我的结果略有不同
bw = [ 0 0 0 0; 0 1 1 0; 0 0 0 0];
imdilate(bw,[1 0;1 1;0 0])
ans =
0 1 1 0
0 1 1 1
0 0 0 0
请注意,我使用了稍微不同的strel
:我在底部添加了一行零。我这样做是为了遵守“原产地左下角”的要求。
根据matlab's strel
doc,你可以看到要求是strel的“origin”是左下角:
nhood
的中心(或原点)是其中心元素,由floor((size(nhood) + 1)/2)
给出。
为了让垂直中心位于第二行(而不是第一行),我在strel
添加了一个空行。