-1

Using imageio.imread instead of scipy.misc.imread (because it is depreciated) is giving me an issue. I want to perform something like this but using imageio:

for file_indexes in duplicates[:30]:
try:
    plt.subplot(121), plt.imshow(imread(files_list[file_indexes[1]]))
    plt.title(file_indexes[1]), plt.xticks([]), plt.yticks([])

When I try the following I get the error

File "<ipython-input-18-2b05f47215d7>", line 4
    plt.subplot(121),img = imageio.imread(files_list[file_indexes[1]])
    ^
SyntaxError: can't assign to function call

That's what I've tried:

for file_indexes in duplicates[:30]:
    try:
        plt.subplot(121), img = imageio.imread((files_list[file_indexes[1]]))
        plt.title(file_indexes[1]), plt.xticks([]), plt.yticks([])

In general, I want to replace scipy.misc.imread in the following code with imageio.imread:

for file_indexes in duplicates[:30]:
    try:
    
        plt.subplot(121),plt.imshow(imread(files_list[file_indexes[1]]))
        plt.title(file_indexes[1]), plt.xticks([]), plt.yticks([])

        plt.subplot(122),plt.imshow(imread(files_list[file_indexes[0]]))
        plt.title(str(file_indexes[0]) + ' duplicate'), plt.xticks([]), plt.yticks([])
        plt.show()
    
    except OSError as e:
        continue

What is the right way to use the correct syntax?

HansHirse
  • 18,010
  • 10
  • 38
  • 67
EverydayDeveloper
  • 1,110
  • 4
  • 11
  • 34
  • Your new code has an assignment, which must go to a new line. It mustn't be located after that `plt.subplot(...)` line. – HansHirse Apr 29 '21 at 11:23
  • I want to be able to find duplicates from the dataset: I have pasted the above code. How can I change from that to something workable with Skipy? @HansHirse – EverydayDeveloper Apr 29 '21 at 11:28
  • Your last edit invalidated my comment, and no longer reflects the stated error message. Do you want to have the original SyntaxError fixed (then rollback your edit), or do you need help with some logic (then edit your question accordingly)? Those two are totally different problems/questions. – HansHirse Apr 29 '21 at 11:30
  • I want to be able to do this: https://github.com/moondra2017/Computer-Vision/blob/master/Duplicate%20Images_Lesson%20%231.ipynb But here Skipy is used which is deprecated. When I try to use Image.io it gives me an error. I have kept both versions, where I get error and what I want to achieve as a reference above @HansHirse – EverydayDeveloper Apr 29 '21 at 11:33
  • 2
    Simply replace `plt.imshow(imread(...))` with `plt.imshow(imageio.imread(...))` **WITHOUT** that assignment `img = imageio.imread(...)`. I'm afraid, you haven't understood the error message (and/or my first comment)... – HansHirse Apr 29 '21 at 11:41

1 Answers1

1

The initial error is located here:

plt.subplot(121), img = imageio.imread((files_list[file_indexes[1]]))

Before, there was no assignment, just another simple statement: plt.imshow(...). Now, there's an assigment, which is not allowed in a list of simple statements. To fix this, you'd just need to move

img = imageio.imread(...)

to a separate line.

But, since you only want to switch from the deprecated scipy.misc.imread to imageio.imread, just replace

plt.imshow(imread(...))

with

plt.imshow(imageio.imread(...))
HansHirse
  • 18,010
  • 10
  • 38
  • 67