I have a code that basically takes two images,big image and small image. the small image is being reduced into one row image and then is being subtracted from each row of the big image. The result should be new big- image with different values.
both images are ndarray (more then 2 dimensions ). When I run this code on one row, it works , but when I try to use for loop in order to run it on all the rows in the image, it never stops .
details of the image: -The big image has currently 11 rows with 1024 columns. -The small reduced image has 1 row only with 1024 columns.
This is the code:
import spectral.io.envi as envi
import matplotlib.pyplot as plt
import os
from spectral import *
import numpy as np
#Create the image path
#the path
img_path = r'N:\path\Image_Python\13-8-2019\emptyname_2019-08-13_11-05-46\capture'
resized_path=r'N:\path\Image_Python'
#the specific file
img_dark= 'DARKREF_emptyname_2019-08-13_11-05-46.hdr'
resized_file='resize3.hdr'
#load images
img_dark= envi.open(os.path.join(img_path,img_dark)).load()
resized= envi.open(os.path.join(resized_path,resized_file)).load()
wavelength=[float(i) for i in resized.metadata['wavelength']]
#reduce image into 1 row
dark_1024=img_dark.mean(axis=0)
#the follow command works and was compared with the image in ENVI
#resized[0] suppoose to be row no. 0 in image resized
#so the problem is in the for loop
resized[0]-dark_1024
#Here I have tried to run at the beginning my computation but then it took too much so I tried to run #this count in order to see how many rows it iterate through
#I have tried this also with a== 3,000,000 and it got there
a=0
for i in resized[0,1]:
a=a+1
print(a)
if a==8000:
break
My end goal is to be able to run the process "resize-dark_1024" for each row in my n-dimensional image using for loop
clarification: Whenever I run:
resized[i]-dark_1024[i]
when i is a number. for example i=3, i-4...
it works
edit 2: If I run this with the dark_1024,which has 1 row with 1024 pixels:
a=0
for i in dark_1024:
a=a+1
print(a)
if a==8000:
break
it counts up to 1024: