Created
February 28, 2020 12:59
-
-
Save cnd/a0020b51de4676394b735a6b2b9978a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if file.filename.endswith('.jpg') or file.filename.endswith('.png'): | |
is_dicom = False | |
img = cv2.imdecode(np.fromstring(file.read(), np.uint8), 1) | |
else: | |
is_dicom = True | |
df = dicom.dcmread(file) # .pixel_array | |
slope = float(df.RescaleSlope) | |
intercept = float(df.RescaleIntercept) | |
df_data = intercept + df.pixel_array * slope / 20 | |
img = df_data.astype(np.float32) | |
img = 255 - img | |
img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB) | |
model = load_model(MODEL_NAME) | |
img = cv2.resize(img, (IMAGE_HEIGHT, IMAGE_WIDTH)) | |
img = img.astype("float") / 255.0 | |
img = img_to_array(img) | |
img = np.expand_dims(img, axis=0) | |
classes = model.predict(img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment