0

I am trying to convert a scilab code to python I have the following code:

for ( i = 0:roi_sx:imgg_sx-roi_sx)
    for ( j = 0:roi_sy:imgg_sy-roi_sy)
        intensity = 0;
        for ( m = i+1:1:i+roi_sx )
            for ( n = j+1:1:j+roi_sy )
              intensity = intensity + imgg(m,n);  
              
            end
        end
        if ( intensity < threshold*roi_sx*roi_sy ) then
            imgs(i+1:1:i+roi_sx, j+1:1:j+roi_sy) = zeros(roi_sx, roi_sy);
        end
    end
end

this is what I could come up with:

for i in range(0,imgg_sx-roi_sx,roi_sx):
    for j in (0,imgg_sy-roi_sy,roi_sy):
        intensity = 0
        for m in range (i+1,i+roi_sx,1):
            for n in range (j+1,j+roi_sy,1):
              intensity = intensity + (imggmatrix[m][n])
        if intensity < threshold*roi_sx*roi_sy:
            imgs([i+1 for i in range(i+roi_sx)],[j+1 for j in range(j+roi_sx)]) = np.zeros((roi_sx, roi_sy),dtype=float)
            #np.imgs([i+1 for i in range(i+roi_sx)],[j+1 for j in range(j+roi_sx)]) = np.zeros((roi_sx, roi_sy),dtype=float)

anyone can please help me figure out what is wrong with this line, I appreciate every contribution

imgs([i+1 for i in range(i+roi_sx)],[j+1 for j in range(j+roi_sx)]) = np.zeros((roi_sx, roi_sy),dtype=float)

I got the following error:

  File "C:\Users\medyo\Desktop\MIP\DataMatrix\DataMatrix.py", line 26, in <module>
    imgs([i+1 for i in range(i+roi_sx)],[j+1 for j in range(j+roi_sx)])
TypeError: 'numpy.ndarray' object is not callable
4
  • The "if statement" if intensity < threshold*roi_sx*roi_sy: at its current location will always see intensity = 0. It should be indented under the "for loop". Commented Dec 13, 2022 at 8:23
  • Assuming imgs is a np.array, you should use double square brackets: ’imgs[[.…], [...]] = ...’ Commented Dec 13, 2022 at 8:33
  • Also, there is a missing ’range’ in ’for j in (...):’ I believe Commented Dec 13, 2022 at 8:34
  • welcome. tour, How to Ask, minimal reproducible example. google the error. don't just post a question without research. also learn python syntax. round parentheses are calls, not indexing. Commented Dec 13, 2022 at 9:22

1 Answer 1

0

I didn't try it, but from what I see your code should be like this since The "if statement" if intensity < threshold*roi_sx*roi_sy: at its current location will always see intensity = 0. It should be indented under the "for loop".

for i in range(0,imgg_sx-roi_sx,roi_sx):
    for j in (0,imgg_sy-roi_sy,roi_sy):
        intensity = 0
        for m in range (i+1,i+roi_sx,1):
            for n in range (j+1,j+roi_sy,1):
              intensity = intensity + (imggmatrix[m][n])
              if intensity < threshold*roi_sx*roi_sy:
                imgs([i+1 for i in range(i+roi_sx)],[j+1 for j in range(j+roi_sx)]) = np.zeros((roi_sx, roi_sy),dtype=float)
                #np.imgs([i+1 for i in range(i+roi_sx)],[j+1 for j in range(j+roi_sx)]) = np.zeros((roi_sx, roi_sy),dtype=float)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.