python – Connected Components Equivalency List

I’m writing some Python code to label different objects in my image using connected components. I’m using 4-neighbors to evaluate each pixel’s label in my logic and I’m not using unionfind to create an equevalency list of the labels because I had some trouble understanding it and I don’t have enough time to use it without blantly copying it from someone else.

I’ll explain what I got up until now:

# -*- coding: utf-8 -*-
import cv2
import numpy as np
# input images
fig1 = cv2.imread("fig1.jpg", cv2.IMREAD_UNCHANGED)
# fig2 = cv2.imread("fig2.jpg", cv2.IMREAD_UNCHANGED)
# fig3 = cv2.imread("fig3.jpg", cv2.IMREAD_UNCHANGED)
# fig4 = cv2.imread("fig4.jpg", cv2.IMREAD_UNCHANGED)


def connected_components(img):
    # working with a copy of the image just for good practice
    im = img.copy()
    im = cv2.bitwise_not(im) # inverting image to have white as 0 = not objects
    # normalizing image to have a proper binary image
    im = cv2.normalize(im, None, alpha=0, beta=1, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8U)
    im = cv2.copyMakeBorder(im, 1, 1, 1, 1, cv2.BORDER_CONSTANT, 0) # add padding to work ouside borders
    labels = np.zeros((im.shape(0), im.shape(1)), dtype=int) # create label matrix with the same size of the image
    corr = (0) # create a  correlation array that already includes 0 as being 0
    # this array works like this: position corr(15) = 1 if the label 15 is equivalent to the label 1

    NextLabel = 1 # counts the label that will be placed on the next pixel with no labeled neighbors 
    
        
    # first pass - rastering through the image
    for row in range(1, im.shape(0)):
        for column in range(1, im.shape(1)):
            if im(row, column) > 0: # if the current pixel is not a backgroud pixel            
                if im(row, column - 1) == 0 and im(row - 1, column) == 0: # if both neighboring pixels are 0
                    labels(row, column) = NextLabel
                    corr.append(NextLabel)
                    NextLabel += 1
                elif im(row, column - 1) != 0 and im(row - 1, column) == 0: # if up pixel is 0 and left pixel is 1
                    labels(row, column) = labels(row, column - 1)
                elif im(row, column - 1) == 0 and im(row - 1, column) != 0: # if up pixel is 1 and left pixel is 0
                    labels(row, column) = labels(row - 1, column)
                elif im(row, column - 1) != 0 and im(row - 1, column) != 0: # if both are 1
                    labels(row, column) = min(labels(row, column - 1), labels(row - 1, column))
                    if corr(min(labels(row, column - 1), labels(row - 1, column))) != min(labels(row, column - 1), labels(row - 1, column)): # will explain later
                        corr(max(labels(row, column - 1), labels(row - 1, column))) = corr(min(labels(row, column - 1), labels(row - 1, column)))
                    else:
                        corr(max(labels(row, column - 1), labels(row - 1, column))) = min(labels(row, column - 1), labels(row - 1, column))
 

    #
    for s in range(2): # cheat for the correspondances to work
        for i in range(1, labels.shape(0)-1): # normal way to assign the correspondant value to the label
            for j in range(1, labels.shape(1)-1):
                if labels(i, j) != corr(labels(i, j)):
                    labels(i, j) = corr(labels(i, j))

    elementos = () # list of elements to fix number of elements on the picture
    for i in range(labels.shape(0)):
        for j in range(labels.shape(1)):
            if labels(i, j) not in elementos:
                elementos.append(labels(i, j))

    for i in range(1, labels.shape(0)-1): # fix elements numbers
        for j in range(1, labels.shape(1)-1):
           labels(i, j)  = elementos.index(labels(i, j))
    
    return labels(1:labels.shape(0)-1, 1:labels.shape(1)-1) # returns original image without padding
# , im(1:labels.shape(0)-1, 1:labels.shape(1)-1)



a = connected_components(fig1)
# print(a)

So, in the part I said I’d explain later, I filter out if the correspondant value is assigned to a value that corresponds to itself, if not, I fix it. But it’s not working as expected. It only works if I apply the correspondances multiple times. E.g. if I have 13 corresponding to 12, 12 corresponding 11 and 11 corresponding to 1, if I fix it only once I’ll get rid of 13 -> 12, so 13 -> 11, but I want 13 -> 1. How can I assure it’ll always correspond to a number that only corresponds to itself? This is the code snipped that does this:

if corr(min(labels(row, column - 1), labels(row - 1, column))) != min(labels(row, column - 1), labels(row - 1, column)):
                            corr(max(labels(row, column - 1), labels(row - 1, column))) = corr(min(labels(row, column - 1), labels(row - 1, column)))
                        else:
                            corr(max(labels(row, column - 1), labels(row - 1, column))) = min(labels(row, column - 1), labels(row - 1, column))

This is the image I’m using:

fig1

My results for this image are as follows:

corr = (0, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 11, 1, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 48, 1, 1, 52, 52, 52, 52, 52, 52, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57)

elementos = (0, 1, 2, 52)

labels (with cheat) = result with cheat

labels (without cheat) = result without cheat

As you can see, there are some objects that have two values inside. If I use the “cheat” I can get rid of those, but I don’t think this cheat has a fixed value and I don’t want to let it there, because it’s wrong.

To see these array values just use a breakpoint on the return line and they’ll all show up!

hooks – SharePoint online search query from Drupal in logged in user context, which is connected through SIMPLESAML SSO (Azure AD IDP) with PHP application

Below is problem description –
I have sharepoint online and its URL is like – https://abc.sharepoint.com

Above sharepoint is connected through SSO (Office 365 Azure AD IDP and SAML)

I have another Drupal 8 application like – https://drupalapp.something.com

It is also connected through same SSO (Office Azure AD and SAML) so that if user login through either of application through SSO then he is allowed to login in another application as well. It means application is Single sign on enabled. and its working fine.

Now as a user, i am able to login through drupalapp.something.com using SSO (office 365 azure AD and SAML ). Now after user login being developer, i need to show recent modified SharePoint document from SharePoint online using SharePoint REST query but condition is that, it should fetch only documents on which logged in user has permission to show.

Brief requirement –

The requirements is to be able to make REST queries to SharePoint online but when the REST query is made, the person the query is for must only see the results based on their security context.

So if user1 has access to a SharePoint folder but user2 has not, then when the REST call is made they will each see a different set of results.

Example: user1 has access to abc.sharepoit.com/abcfolder/afile.pdf. User2 does not have access to the folder abc.sharepoit.com/abcfolder/ and so he will not have access to abc.sharepoit.com/abcfolde/afile.pdf.

If some updates this document it becomes a “Latest Update”. User1 will see it in the Latest documents but User2 will not.

I tried using PHPSPO library (https://github.com/vgrem/phpSPO) and it giving me result but this library is giving me result based on admin credential which I pass to connect SharePoint.

How can i achieve this in logged in user context. Considering user is already login through SSO.

I also tried to make AJAX query from drupalapp but it always giving me CORS error.

Please help me to solve this problem.

Thanks

Windows 10 to android bluetooth, windows say paired and connected, android says paired but cant connect

Trying to link s20+5g to windows 10 desktop via bluetooth. Have tried this on two different machines and received the same result. They pair fine, then when I try to connect them windows say they connected, but the phone says it cannot connect and will not do anything with the bluetooth connection. Is there any settings I can change on the phone (in the developer settings maybe?) or the desktop to try and fix this? I do not have root access on the phone (US snapdragon unfortunately). The bluetooth driver is updated to the latest version, and I have updated windows to the latest version in my attempts to fix this.

security – T2 chip encryption benefits: “Your encrypted SSDs automatically mount and decrypt when connected to you mac.”

I just read the mac page about SSD encryption by the T2 chip here

Always back up your content to a secure external drive or other secure backup location so that you can restore it, if necessary. You should also turn on FileVault for additional security, because without FileVault enabled, your encrypted SSDs automatically mount and decrypt when connected to your Mac.

I am confused. Isn’t encryption only useful when it does not automatically decrypt? This seems rather useless. I guess it prevents certain kinds of attacks: someone steals the SSD from the device using advanced techniques without stealing the whole laptop. In this case, doesn’t it just make sense to take the whole laptop?

What is the purpose of the encryption provided by the T2 chip? I know the benefits of FileVault 2 though, which also makes use of the T2 chip. However, to decrypt this FileVault you need your user password. To decrypt the initial T2 encryption, you need nothing?

networking – how to make a pc to be connected with another pc directly, while still let it connect to the internet via network cable

I have my pc which is connected into our LAN via a network cable, and through which internet can be visited.

Now one of our teammates has his pc, which has no right to connect to our LAN.

Problem is that my teammate and I are now developing a web application, I build the backend and he build the frontend, and we need to communicate with each other through predefined http RESTful api.

I need to communicate with my teammate, while still can access our LAN. What is the best practise to do so? Both of us are using windows.

I tried to open a 360wifi, which can make my laptop pc to setup a wifi, and my teammate’s laptop can access this wifi can visit the internet. But he cannot visit my backend service by the ip address of my laptop in the LAN network(ping returns error.).

I guess I need two network card, one for our LAN, aonther for my teammate, we can connect with each other via directly network cable connection.

Highly homogeneous connected $T_2$-spaces

Is there a connected $T_2$-space $(X,tau)$ with $|X|>1$ and the following property?

Whenever $A$ is a subset of $X$ with $|A|<|X|$ and $f:Ato A$ is a bijection, there is a homeomorphism $varphi:Xto X$ such that $varphirestriction_A = f$.

How can I examine the subnetworks of a nearly fully connected graph?

I have an almost fully connected graph in python with roughly 3k nodes and 9M edges. Each node in this graph is represented by a point in R3 and each edge represents the distance between them with a weight given by a weight matrix.

My goal is to visualize subnetworks (areas where points close to each other also have a dense set of edge weights) where the subnetwork is colored by the given weight. However, this is extremely computationally expensive, as there are 9M edges. I’m looking for an algorithm that can either return the subnetworks, visualize these subnetworks, or something similar.

graphics card – Monitors connected to on-board HMDI and VGA ports shows blank after installing Nvidia Driver | Fedora 32

I am using a desktop with 3 monitors.

2 x 21-inch Dell monitors
1 x 34-inch LG monitor

The 2 Dell monitors, one is connected to the VGA port on-board, and the second one is connected to the onboard HDMI port.

The third and the large monitor 34 inches LG is connected to the HDMI port of NVIDIA GeForce GTX 1650 SUPER.

The system was using Windows 10, but I replaced it with Fedora 32 KDE last week, also installed Nvidia driver and CUDA successfully then. It has been working well until today, but I have no idea what really happened in the system or if some system update has undergone without my knowledge, when I tried to boot up the machine today morning, all I can see only the large 32inch LG monitor connected to Nvidia graphic card is showing up. The system is showing disconnected status for the rest two Dell monitors connected on-board VGA and HDMI ports which are using Intel onboard integrated GPU.

^ john @ fedora ~ > $ lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation HD Graphics 510 (rev 06)
01:00.0 VGA compatible controller: NVIDIA Corporation TU116 (GeForce GTX 1650 SUPER) (rev a1)

^ john @ fedora ~ > $ sudo xrandr 
Screen 0: minimum 8 x 8, current 2560 x 1080, maximum 32767 x 32767
DVI-D-0 disconnected (normal left inverted right x axis y axis)
HDMI-0 connected primary 2560x1080+0+0 (normal left inverted right x axis y axis) 798mm x 334mm
   2560x1080     59.98*+  74.99    50.00  
   1920x1080     75.00    60.00    59.94    50.00  
   1680x1050     59.95  
   1600x900      60.00  
   1280x1024     75.02    60.02  
   1280x800      59.81  
   1280x720      60.00    59.94    50.00  
   1152x864      60.00  
   1024x768      75.03    60.00  
   800x600       75.00    60.32  
   720x576       50.00  
   720x480       59.94  
   640x480       75.00    59.93    59.94  
DP-0 disconnected (normal left inverted right x axis y axis)
DP-1 disconnected (normal left inverted right x axis y axis)

^ john @ fedora ~ > $ sudo lsmod | grep 'i915|nvidia|nouveau'
i2c_nvidia_gpu         16384  0
nvidia_drm             57344  9
nvidia_modeset       1216512  24 nvidia_drm
nvidia              27701248  1286 nvidia_modeset
i915                 2621440  1
i2c_algo_bit           16384  1 i915
drm_kms_helper        262144  2 nvidia_drm,i915
cec                    61440  2 drm_kms_helper,i915
drm                   626688  13 drm_kms_helper,nvidia_drm,i915
video                  53248  2 asus_wmi,i915

^ john @ fedora ~ > $ sudo nvidia-smi 
Mon Oct 12 18:14:56 2020       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 455.28       Driver Version: 455.28       CUDA Version: 11.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX 165...  Off  | 00000000:01:00.0  On |                  N/A |
|  0%   49C    P8    12W / 100W |    465MiB /  3911MiB |      4%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1366      G   /usr/libexec/Xorg                 183MiB |
|    0   N/A  N/A      1563      G   /usr/bin/kwin_x11                  86MiB |
|    0   N/A  N/A      1566      G   /usr/bin/plasmashell               64MiB |
|    0   N/A  N/A      1842      G   ...akonadi_archivemail_agent        2MiB |
|    0   N/A  N/A      1853      G   .../akonadi_mailfilter_agent        2MiB |
|    0   N/A  N/A      1860      G   ...n/akonadi_sendlater_agent        2MiB |
|    0   N/A  N/A      1862      G   ...nadi_unifiedmailbox_agent        2MiB |
|    0   N/A  N/A      2060      G   ...AAAAAAAAA= --shared-files      113MiB |
+-----------------------------------------------------------------------------+


^ john @ fedora ~ > $ echo $XDG_SESSION_TYPE
x11

^ john @ fedora ~ > $ sudo grep GRUB_CMDLINE_LINUX /etc/sysconfig/grub
GRUB_CMDLINE_LINUX="resume=/dev/mapper/fedora_fedora-swap rd.lvm.lv=fedora_fedora/root rd.lvm.lv=fedora_fedora/swap rhgb quiet rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1"

^ john @ fedora ~ > $ cat /etc/modprobe.d/blacklist.conf 
blacklist nouveau
options nouveau modeset=0
options nvidia-drm modeset=1

^ john @ fedora ~ > $ cat /etc/X11/xorg.conf
# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig:  version 455.28


Section "ServerLayout"
    Identifier     "Layout0"
    Screen      0  "Screen0" 0 0
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
EndSection

Section "Files"
EndSection

Section "InputDevice"

    # generated from default
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Protocol" "auto"
    Option         "Device" "/dev/input/mice"
    Option         "Emulate3Buttons" "no"
    Option         "ZAxisMapping" "4 5"
EndSection

Section "InputDevice"

    # generated from default
    Identifier     "Keyboard0"
    Driver         "kbd"
EndSection

Section "Monitor"
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "Unknown"
    Option         "DPMS"
EndSection

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
EndSection

Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    SubSection     "Display"
        Depth       24
    EndSubSection
EndSection

nvidia-bug-report https://www.dropbox.com/s/tq3ozp5zsy426vr/nvidia-bug-report.log.gz?dl=0

nvidia-settings https://imgur.com/a/XD6o5OW

What could be wrong here?.

oracle – Should I be using this to export the data using the SQL Developer ‘Data Pump Export Wizard’ connected as a DBA?

I am trying to learn more about Oracle databases in my spare time. I have Oracle Enterprise available in a Docker Container. I am a developer rather than a DBA. I have plenty of experience with SQL Server.

I am trying to use the data pump feature. So far I have done this:

  1. Created a user called dummy and created a table (Dummy.table1).
  2. Added a few rows to table1.
  3. Created a user called admin and given this user dba access.
  4. Login to SQL Developer as admin and select: View/DBA.
  5. Connect to my database and use Data Pump Export Wizard to create a dump file.
  6. Generate a .sql file from the .dmp file.

I have tried all four options (Database; Tablespaces; Schemas and Tabeles) under: ‘Types to be exported in data pump’, selecting ‘Data and DDL’ each time, however I cannot see the INSERT statements, which should be created for Dummy.table1. Why is this?

The only thing I can think of is that there is a menu item called: ToolsDatabase Export. Should I be using this to export the data? I would of thought that the data should be exported when using the Data Pump Export Wizard; connected as a DBA?

c++ – QTcpSocket does not emit connected()

I’m using QT5 and starting out with a basic Server/Client setup. I’m looking at going single threaded for both apps as there is no heavy processing on network data. Now, from everything I’ve read and researched here, when using asynchronous approach, you don’t use waitForXXXX() otherwise it messes up all the signals and slots.
The problem – On the client end, the connected() signal is either never emitted or never processed, even though the server consoles tells me that a new client has connected. I’ve been working on the same issue for 2 weeks now and couldn’t find the exact same issue anywhere. I’ve stripped back both apps to the minimum and still no luck – also stripped out the UI part now – I just want see the console working. I have also tried switching to public slots and changing the signal/slot connection type and still have the same problem.

If you require code from the server, please let me know, but here is the basics of the client:

main.cpp

#include "QGameSocket.h"
#include <QtWidgets/QApplication>

#include <windows.h>

int main(int argc, char *argv())
{
    AllocConsole();
    freopen( "conin$", "r", stdin );
    freopen( "conout$", "w", stdout );
    freopen( "conout$", "w", stderr );

    QApplication a( argc, argv );
    QGameSocket* pSocket = new QGameSocket();

    return a.exec();
}

QGameSocket.h

#ifndef _QGAMESOCKET_H
#define _QGAMESOCKET_H

#include <QtNetwork/qtcpsocket.h>
#pragma comment ( lib, "Qt5Network.lib" )

class QGameSocket: public QObject
{
    Q_OBJECT

public:
    explicit QGameSocket( QObject* pParent = 0 );
    ~QGameSocket();

private slots:
    void __OnConnected();
    void __OnReadyRead();

private:
    QTcpSocket* m_pSocket;
};

#endif

QGameSocket.cpp

#include "QGameSocket.h"
#include <qdatastream.h>

QGameSocket::QGameSocket( QObject* pParent ) :  
    QObject( pParent )
{
    m_pSocket = new QTcpSocket();
    
    connect( m_pSocket, SIGNAL( connected() ), this, SLOT( __OnConnected() ) );
    connect( m_pSocket, SIGNAL( readyRead() ), this, SLOT( __OnReadyRead() ) );

    const QString strHost = "127.0.0.1";

    qDebug() << "Connecting to host ...";
    m_pSocket->connectToHost( strHost, 27015 );
}

QGameSocket::~QGameSocket()
{
    m_pSocket->deleteLater();
}

void QGameSocket::__OnConnected()
{
    qDebug() << "Successfully connected to host!";
}

void QGameSocket::__OnReadyRead()
{
    //handle messages
}

Any help would be much appreciated, thank you!