Dual-color augmented reality waveguide display for color vision assistance using color tracking.
The 1 match
- [1] § STAR★Methods › Method details › ANN for HSV-based red color object extraction ↔ AI_HSV_color extraction.py, lines 87–98 · score 0.58 · activation function, OpenCV, sigmoid, layer, Model, ANN
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
Python · 297 lines · 12 KB · no license · 1 match
- import cv2
- import os
- import numpy as np
- import time
- from sklearn.model_selection import train_test_split
- from sklearn.metrics import accuracy_score, precision_score, recall_score
- import xml.etree.ElementTree as ET
- import matplotlib.pyplot as plt
- import matplotlib.image as mpimg
- # 단일 이미지에서 훈련 데이터 수집
- def collect_training_data(image_path, lower_red1, upper_red1, lower_red2, upper_red2, save_mask=False, output_dir='masks'):
- image = cv2.imread(image_path)
- if image is None:
- print("Error: 이미지를 로드할 수 없습니다. 파일이 유효한 이미지인지 확인하세요.")
- return None, None
- # HSV 색상 공간으로 변환
- hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
- # 마스크 생성
- mask1 = cv2.inRange(hsv, lower_red1, upper_red1)
- mask2 = cv2.inRange(hsv, lower_red2, upper_red2)
- mask = cv2.bitwise_or(mask1, mask2)
- # 마스크 저장 (디버깅용)
- if save_mask:
- if not os.path.exists(output_dir):
- os.makedirs(output_dir)
- mask_path = os.path.join(output_dir, os.path.basename(image_path).split('.')[0] + '_mask.png')
- cv2.imwrite(mask_path, mask)
- print(f"마스크가 {mask_path}에 저장되었습니다.")
- # 결과 이미지 생성
- hsv_flat=hsv.reshape(-1, 3).astype(np.float32)
- hsv_flat[:,0] /= 179.0 # Hue 정규화
- hsv_flat[:,1] /= 255.0 # Saturation 정규화
- hsv_flat[:,2] /= 255.0 # Value 정규화
- labels=(mask.reshape(-1) / 255).astype(np.float32)
- return hsv_flat, labels
- # 다중 이미지 데이터 수집
- def collect_training_data_from_directory(directory, lower_red1, upper_red1, lower_red2, upper_red2):
- hsv_list = []
- labels_list = []
- training_dir = r'C://Users//user//Desktop//CVDcoding//training_images'
- # 훈련 이미지 디렉토리
- if not os.path.exists(training_dir):
- print(f"Error: 디렉토리가 {training_dir}에 존재하지 않습니다.")
- return None, None
- for filename in os.listdir(directory):
- if filename.endswith('.jpg') or filename.endswith('.png'):
- image_path = os.path.join(directory, filename)
- hsv, labels = collect_training_data(image_path, lower_red1, upper_red1, lower_red2, upper_red2, save_mask=True)
- if hsv is not None:
- hsv_list.append(hsv)
- labels_list.append(labels)
- if hsv_list:
- hsv_data = np.vstack(hsv_list)
- labels_data = np.hstack(labels_list)
- return hsv_data, labels_data
- else:
- print("Warning: 처리된 이미지가 없습니다.")
- return None, None
- # 데이터 증강
- def augment_data(hsv_data, labels, num_augmentations=5):
- augmented_hsv = []
- augmented_labels = []
- for i in range(len(hsv_data)):
- h, s, v = hsv_data[i]
- label = labels[i]
- augmented_hsv.append([h, s, v])
- augmented_labels.append(label)
- for _ in range(num_augmentations):
- h_aug = (h + np.random.uniform(-0.028, 0.028)) % 1.0 # Hue ±5/179
- s_aug = np.clip(s * np.random.uniform(0.9, 1.1), 0, 1.0)
- v_aug = np.clip(v * np.random.uniform(0.8, 1.2), 0, 1.0)
- augmented_hsv.append([h_aug, s_aug, v_aug])
- augmented_labels.append(label)
- return np.array(augmented_hsv, dtype=np.float32), np.array(augmented_labels, dtype=np.float32)
- # ANN 훈련
- def train_ann(hsv_data, labels, model_path='mlp_model.xml'):
- mlp = cv2.ml.ANN_MLP_create()
- mlp.setLayerSizes(np.array([3, 20, 10, 1]))
- mlp.setActivationFunction(cv2.ml.ANN_MLP_SIGMOID_SYM)
- mlp.setTermCriteria((cv2.TERM_CRITERIA_COUNT, 300, 0.001))
- mlp.train(hsv_data, cv2.ml.ROW_SAMPLE, labels.reshape(-1, 1))
- mlp.save(model_path)
- print(f"모델이 {model_path}에 저장되었습니다.")
- return mlp
- # 실시간 비디오 처리
- def process_video_with_ann(model_path='mlp_model.xml'):
- # 트랙바 창 생성
- cv2.namedWindow("Trackbars")
- capture = cv2.VideoCapture(0, cv2.CAP_DSHOW) # 카메라 인덱스에 따라 변경
- capture.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
- capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
- try:
- mlp = cv2.ml.ANN_MLP_load(model_path)
- except:
- print(f"Error: 모델 파일 {model_path}을 로드할 수 없습니다. 먼저 모델을 훈련시키세요.")
- return
- while True:
- start_time = time.time()
- ret, frame = capture.read()
- if not ret:
- print("Error: 프레임을 읽을 수 없습니다.")
- break
- ori_frame = frame.copy()
- hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
- hsv_flat = hsv.reshape(-1, 3).astype(np.float32)
- hsv_flat[:,0] /= 179.0
- hsv_flat[:,1] /= 255.0
- hsv_flat[:,2] /= 255.0
- _, predictions = mlp.predict(hsv_flat)
- mask = (predictions > 0.8).reshape(frame.shape[:2]).astype(np.uint8) * 255
- # 적색 픽셀을 흰색으로, 나머지는 검정색으로 표시
- masked_frame = np.zeros_like(ori_frame)
- masked_frame[mask == 255] = [255, 255, 255]
- # 프레임당 처리 시간과 FPS 계산
- time_elapsed=time.time() - start_time
- fps=1/time_elapsed if time_elapsed > 0 else 0
- cv2.putText(masked_frame, f"FPS: {fps:.2f}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
- cv2.putText(masked_frame, f"Time: {time_elapsed*1000:.2f} ms", (10, 60), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
- cv2.imshow("Original Frame", ori_frame)
- cv2.imshow("Masked Frame", masked_frame)
- if cv2.waitKey(33) == ord('q'):
- break
- capture.release()
- cv2.destroyAllWindows()
- # 가중치 분포 시각화
- def plot_weights_distribution(model_path='mlp_model.xml'):
- try:
- tree = ET.parse(model_path)
- root = tree.getroot()
- weight_elements = root.findall('opencv_ml_ann_mlp/weights/_')
- num_layers=len(weight_elements)
- if num_layers == 0:
- print("Error: 가중치 정보가 없습니다.")
- return
- fig, axes=plt.subplots(num_layers, 1, figsize=(8 * num_layers, 6))
- if num_layers == 1:
- axes=[axes] # 단일 레이어의 경우 리스트로 변환
- for i, (weight_array, ax) in enumerate(zip(weight_elements, axes)):
- print(f"가중치 분포 figure 생성: 레이어 {i+1}")
- weight_str = weight_array.text.strip()
- weights = np.fromstring(weight_str, sep=' ')
- ax.hist(weights, bins=50, edgecolor='black')
- ax.set_title(f'Layer {i+1} Weights Distribution')
- ax.set_xlabel('Weight Value')
- ax.set_ylabel('Frequency')
- ax.grid(True)
- plt.tight_layout()
- plt.show(block=False)
- plt.pause(0.001) # 잠시 대기하여 그래프를 업데이트
- except Exception as e:
- print(f"XML 파싱 오류: {e}")
- # HSV 결정 경계 시각화
- def plot_hsv_decision_boundary_with_data(mlp, hsv_train, labels_train, V_fixed=128, H_step=1, S_step=5):
- V_norm = V_fixed / 255.0
- H_values = np.arange(0, 180, H_step)
- S_values = np.arange(0, 256, S_step)
- H_grid, S_grid = np.meshgrid(H_values, S_values)
- H_flat = H_grid.ravel()
- S_flat = S_grid.ravel()
- V_flat = np.full_like(H_flat, V_norm)
- hsv_points = np.vstack([H_flat / 179.0, S_flat / 255.0, V_flat]).T.astype(np.float32)
- _, predictions = mlp.predict(hsv_points)
- predictions = predictions.reshape(H_grid.shape)
- hsv_train_denorm = hsv_train.copy()
- hsv_train_denorm[:, 0] *= 179.0
- hsv_train_denorm[:, 1] *= 255.0
- hsv_train_denorm[:, 2] *= 255.0
- mask = np.abs(hsv_train_denorm[:, 2] - V_fixed) < 10
- hsv_subset = hsv_train_denorm[mask]
- labels_subset = labels_train[mask]
- plt.figure(figsize=(10, 8))
- plt.contourf(H_values, S_values, predictions, levels=50, cmap='RdBu', alpha=0.8)
- plt.colorbar(label='Prediction (0: Non-Red, 1: Red)')
- red_points = hsv_subset[labels_subset == 1]
- non_red_points = hsv_subset[labels_subset == 0]
- if len(red_points) > 0:
- plt.scatter(red_points[:, 0], red_points[:, 1], c='red', label='Red Pixels', alpha=0.5, s=10)
- if len(non_red_points) > 0:
- plt.scatter(non_red_points[:, 0], non_red_points[:, 1], c='blue', label='Non-Red Pixels', alpha=0.5, s=10)
- plt.xlabel('Hue (0-179)')
- plt.ylabel('Saturation (0-255)')
- plt.title(f'ANN Decision Boundary with Training Data at V={V_fixed}')
- plt.legend()
- plt.grid(True)
- plt.show(block=False)
- plt.pause(0.001) # 잠시 대기하여 그래프를 업데이트
- # 메인 실행
- if __name__ == "__main__":
- # 적색 범위 설정
- lower_red1 = np.array([0, 100, 100])
- upper_red1 = np.array([10, 255, 255])
- lower_red2 = np.array([170, 100, 100])
- upper_red2 = np.array([179, 255, 255])
- # 훈련 데이터 수집
- training_dir = r'C:/Users//user//Desktop//CVDcoding//training_images' # 훈련 이미지 디렉토리
- hsv_data, labels = collect_training_data_from_directory(training_dir, lower_red1, upper_red1, lower_red2, upper_red2)
- # 디렉토리 생성 또는 확인
- if not os.path.exists(training_dir):
- os.makedirs(training_dir)
- print(f"디렉토리 {training_dir}를 생성했습니다. 이미지를 추가한 후 다시 실행하세요.")
- exit()
- if hsv_data is not None:
- hsv_train, hsv_test, labels_train, labels_test = train_test_split(hsv_data, labels, test_size=0.2, random_state=42)
- # 데이터 균형 조정
- red_indices = np.where(labels_train == 1)[0]
- non_red_indices = np.where(labels_train == 0)[0]
- num_red = len(red_indices)
- if num_red == 0:
- print("Error: No red pixels in training data.")
- else:
- # 디버깅: 데이터 크기 확인
- print(f"hsv_train shape: {hsv_train.shape}, labels_train shape: {labels_train.shape}")
- print(f"red_indices count: {len(red_indices)}, non_red_indices count: {len(non_red_indices)}")
- if len(non_red_indices) > num_red:
- sampled_non_red_indices = np.random.choice(non_red_indices, size=num_red, replace=False)
- else:
- sampled_non_red_indices = non_red_indices
- selected_indices = np.concatenate([red_indices, sampled_non_red_indices])
- # 인덱스 유효성 검증
- max_index = hsv_train.shape[0] - 1
- if np.any(selected_indices > max_index):
- print(f"Error: selected_indices contains invalid indices. Max valid index: {max_index}")
- selected_indices = selected_indices[selected_indices <= max_index]
- np.random.shuffle(selected_indices)
- # 데이터 선택
- hsv_selected = hsv_train[selected_indices]
- labels_selected = labels_train[selected_indices]
- max_samples = 1000 # 시스템 성능에 따라 조정
- if len(hsv_selected) > max_samples:
- indices = np.random.choice(len(hsv_selected), max_samples, replace=False)
- hsv_selected = hsv_selected[indices]
- labels_selected = labels_selected[indices]
- # 데이터 증강
- hsv_aug, labels_aug = augment_data(hsv_selected, labels_selected, num_augmentations=5)
- # print("debugging_1")
- # ANN 훈련
- mlp = train_ann(hsv_aug, labels_aug)
- # 테스트 데이터로 평가
- _, predictions_test = mlp.predict(hsv_test)
- predictions_test = (predictions_test > 0.8).astype(int).flatten()
- accuracy = accuracy_score(labels_test, predictions_test)
- precision = precision_score(labels_test, predictions_test)
- recall = recall_score(labels_test, predictions_test)
- print(f"Test Accuracy: {accuracy:.4f}")
- print(f"Test Precision: {precision:.4f}")
- print(f"Test Recall: {recall:.4f}")
- # 실시간 비디오 처리
- process_video_with_ann()
AI_HSV_color extraction.py at commit d560e29, no license · at the source
Overview
- Department of Intelligent Semiconductor Engineering, Chung-Ang University, Seoul 06974, Republic of Korea
- School of Electrical and Electronic Engineering, Chung-Ang University, Seoul 06974, Republic of Korea
Abstract
Color vision deficiency (CVD) impairs the discrimination of specific color pairs, particularly red and green, and curative treatments remain unavailable. Existing assistive approaches, such as tinted glasses, contact lenses, and screen-based recoloring methods, can improve color discrimination, but these approaches either modify the entire visual field globally or are constrained to fixed display environments. Here, we propose an augmented reality (AR) display that captures real-time real-world scenes, identifies regions of perceptual difficulty, and superimposes virtual content to assist users with CVD by integrating artificial neural network-based color tracking. The AR system incorporates a fabricated holographic optical element (HOE) integrated into compact waveguide optics, functioning as a dual-color narrowband coupler within a transparent combiner. Optical measurements confirm selective wavelength coupling, and proof-of-concept demonstrations show spatially selective overlay on the target objects. These results suggest the feasibility of HOE-based AR color vision assistance as a wearable approach for targeted color-discrimination scenarios.
Reproduced under the paper's license (CC BY), from the paper cited above.
Repository
Its files are read in the Code ↔ Paper reader above, with 1 match between paragraphs and lines of code.
qldthe8675/Color-extraction
d560e29600f68754ec34abd7411a6979aafd890f, 30 April 2026Availability: 1 check, the latest on 27 September 2026: the link answers
- 27 September 2026: the link answers
2 files
- AI_HSV_color extraction.py, Python, 297 lines, 1 match
- README.md, Text, 63 lines
The paper's code and data availability statement is in the Data section.
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 1 script, each with its path and the digest of its content;
- 1 match between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
No dataset and no data link were found in the paper.
Data and code availability
All data reported in this study will be shared by the lead contact upon request.
All original codes used in this study are publicly available on GitHub (https://
Any additional information required to reanalyze the data reported in this study is available from the lead contact upon request.
Reproduced under the paper's license (CC BY), from the paper cited above.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 2, 28 September 2026
- Authors: added Young-Wan Choi (0000-0002-9608-4549); removed Young-Wan Choi
Version 1, 27 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 4 authors, 3 keywords, 4 funders, 39 references.
Cite
This paper
Cho, S.-H., Baek, D.-H., Choi, W. J., & Choi, Y.-W. (2026). Dual-color augmented reality waveguide display for color vision assistance using color tracking. iScience, 29(7), 116392. https://
BibTeX
@article{cho2026dual,
author = {Cho, Seong-Hyeon and Baek, Do-Hun and Choi, Woo June and Choi, Young-Wan},
title = {{Dual-color augmented reality waveguide display for color vision assistance using color tracking}},
journal = {iScience},
year = {2026},
month = jun,
volume = {29},
number = {7},
pages = {116392},
publisher = {Elsevier},
issn = {2589-0042},
doi = {10.1016/
url = {https://
pmid = {42325546},
pmcid = {PMC13277613}
}
RIS
TY - JOUR
AU - Cho, Seong-Hyeon
AU - Baek, Do-Hun
AU - Choi, Woo June
AU - Choi, Young-Wan
TI - Dual-color augmented reality waveguide display for color vision assistance using color tracking
T2 - iScience
J2 - iScience
PY - 2026
DA - 2026/
VL - 29
IS - 7
SP - 116392
SN - 2589-0042
PB - Elsevier
DO - 10.1016/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1016/
"type": "article-journal",
"title": "Dual-color augmented reality waveguide display for color vision assistance using color tracking",
"container-title": "iScience",
"author": [
{
"family": "Cho",
"given": "Seong-Hyeon"
},
{
"family": "Baek",
"given": "Do-Hun"
},
{
"family": "Choi",
"given": "Woo June"
},
{
"family": "Choi",
"given": "Young-Wan"
}
],
"container-title-short":
"volume": "29",
"issue": "7",
"page": "116392",
"DOI": "10.1016/
"PMID": "42325546",
"PMCID": "PMC13277613",
"ISSN": "2589-0042",
"publisher": "Elsevier",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
6,
12
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1007/s00429-026-03166-w [code]
- Autoencoders for unsupervised analysis of rat myeloarchitecture.Journal: Brain structure & functionIn common: OpenCV, scikit-learn, Matplotlib, 1 other tool
- [2] doi: [code]
- Real-time closed-loop feedback system for mouse mesoscale cortical signal and movement controlJournal: eLifeIn common: OpenCV, scikit-learn, Matplotlib, 1 other tool
- [3] doi:10.7554/elife.100880 [code]
- An applicable and efficient retrograde monosynaptic circuit mapping tool for larval zebrafish.Journal: eLifeIn common: OpenCV, scikit-learn, Matplotlib, 1 other tool
- [4] doi:10.1038/s42003-026-10957-8 [code]
- Brain defence by the extracellular matrix protein Cochlin.Journal: Communications biologyIn common: OpenCV, scikit-learn, Matplotlib, 1 other tool
- [5] doi:10.3390/diagnostics16172861 [code]
- Microstructural Changes in the Corpus Callosum in Different Forms of Sporadic Age-Related Cerebral Small Vessel Disease.Journal: Diagnostics (Basel, Switzerland)In common: OpenCV, scikit-learn, Matplotlib, 1 other tool
- [6] doi:10.1002/hipo.70131 [code]
- Decoding Medial Entorhinal Cortical Dynamics Produces Planning-Like Alternations in Hippocampal theta Sequences.Journal: HippocampusIn common: OpenCV, scikit-learn, Matplotlib, 1 other tool
- [7] doi:10.1038/s43856-026-01817-x [code]
- Visual prompt engineering for multimodal and irregularly sampled medical data.Journal: Communications medicineIn common: OpenCV, scikit-learn, Matplotlib, 1 other tool
- [8] doi:10.1016/j.isci.2026.117375 [code]
- Motor priming is associated with widespread recruitment into neural ensembles and more rapid ensemble transitions.Journal: iScienceIn common: OpenCV, scikit-learn, Matplotlib, 1 other tool
- [9] doi:10.1038/s41598-026-61605-4 [code]
- Learning precise segmentation of neurofibrillary tangles from rapid manual point annotations.Journal: Scientific reportsIn common: OpenCV, scikit-learn, Matplotlib, 1 other tool
- [10] doi:10.1126/sciadv.aed4172 [code]
- Locomotion optimizes sensory representations through a computational principle shared by rodents and primates.Journal: Science advancesIn common: OpenCV, scikit-learn, Matplotlib, 1 other tool
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 1 repository of the authors' code, each at its verified commit and with its license, 1 script, and 1 match between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:8366eb2edb30c7f2…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
