I need to correct the script for coloring map
11 ビュー (過去 30 日間)
古いコメントを表示
%## Edited so that code runs here
clc;
close all;
clear;
% Read the geological map
% [file, path] = uigetfile('*.jpg', 'Select the Geological Map File');
path = './';
file = 'Geological map of Mobrun Sulfied.jpg';
map_image = imread(fullfile(path, file));
% Display the original map
figure;
imshow(map_image);
title('Original Map');
% Convert to RGB if the image is grayscale
if size(map_image, 3) == 1
map_image = cat(3, map_image, map_image, map_image);
end
% Define masks for regions based on RGB values
% Inspect the RGB values of each region using 'impixelinfo' or similar
% Example: Rhyolite, Andesite, and Meta-sediments regions
% Replace these thresholds with specific RGB ranges based on your map
ryolite_mask = (map_image(:,:,1) > 200 & map_image(:,:,2) < 100 & map_image(:,:,3) < 100); % Example: Red shades
andesite_mask = (map_image(:,:,1) < 100 & map_image(:,:,2) > 150 & map_image(:,:,3) < 100); % Example: Green shades
meta_sediments_mask = (map_image(:,:,1) < 100 & map_image(:,:,2) < 100 & map_image(:,:,3) > 150); % Example: Blue shades
% Create a copy of the map for coloring
colored_map = map_image;
% Apply colors to the masks
% Rhyolite - Red
colored_map(:,:,1) = colored_map(:,:,1) + uint8(ryolite_mask) * 255; % Red channel
colored_map(:,:,2) = colored_map(:,:,2) - uint8(ryolite_mask) * 255; % Green channel
colored_map(:,:,3) = colored_map(:,:,3) - uint8(ryolite_mask) * 255; % Blue channel
% Andesite - Green
colored_map(:,:,1) = colored_map(:,:,1) - uint8(andesite_mask) * 255;
colored_map(:,:,2) = colored_map(:,:,2) + uint8(andesite_mask) * 255;
colored_map(:,:,3) = colored_map(:,:,3) - uint8(andesite_mask) * 255;
% Meta-sediments - Blue
colored_map(:,:,1) = colored_map(:,:,1) - uint8(meta_sediments_mask) * 255;
colored_map(:,:,2) = colored_map(:,:,2) - uint8(meta_sediments_mask) * 255;
colored_map(:,:,3) = colored_map(:,:,3) + uint8(meta_sediments_mask) * 255;
% Display the colored map
figure;
imshow(colored_map);
title('Colored Geological Map');
% Save the colored map
imwrite(colored_map, 'Colored_Geological_Map_Automatic.jpg');
1 件のコメント
Cris LaPierre
2025 年 1 月 20 日 14:48
編集済み: Cris LaPierre
2025 年 1 月 20 日 14:51
As shown below, your RGB thresholds are not selecting anything in the image. I'm not sure what to expect for a grayscale image, but based on the comments in the script, I'd suggest revisiting your threshold values.
% Define masks for regions based on RGB values
% Inspect the RGB values of each region using 'impixelinfo' or similar
% Example: Rhyolite, Andesite, and Meta-sediments regions
My suspicion is the hatching or texturing used to 'color' the image will make it challenging for a thresholding approach to produce the desired results.
map_image = imread('Geological ma...n Sulfied.jpg');
% Replace these thresholds with specific RGB ranges based on your map
ryolite_mask = (map_image(:,:,1) > 200 & map_image(:,:,2) < 100 & map_image(:,:,3) < 100); % Example: Red shades
andesite_mask = (map_image(:,:,1) < 100 & map_image(:,:,2) > 150 & map_image(:,:,3) < 100); % Example: Green shades
meta_sediments_mask = (map_image(:,:,1) < 100 & map_image(:,:,2) < 100 & map_image(:,:,3) > 150); % Example: Blue shades
figure
imshow(ryolite_mask)
figure
imshow(andesite_mask)
figure
imshow(meta_sediments_mask)
回答 (2 件)
Les Beckham
2025 年 1 月 20 日 14:34
You need to reexamine the logic you are using to determine the masks. All three masks are all zero, thus no coloring.
% clc;
% close all;
% clear;
%
% % Read the geological map
% [file, path] = uigetfile('*.jpg', 'Select the Geological Map File');
% map_image = imread(fullfile(path, file));
dir
map_image = imread('Geological ma...n Sulfied.jpg');
% Display the original map
figure;
imshow(map_image);
title('Original Map');
% Convert to RGB if the image is grayscale
if size(map_image, 3) == 1
map_image = cat(3, map_image, map_image, map_image);
end
% Define masks for regions based on RGB values
% Inspect the RGB values of each region using 'impixelinfo' or similar
% Example: Rhyolite, Andesite, and Meta-sediments regions
% Replace these thresholds with specific RGB ranges based on your map
ryolite_mask = (map_image(:,:,1) > 200 & map_image(:,:,2) < 100 & map_image(:,:,3) < 100); % Example: Red shades
andesite_mask = (map_image(:,:,1) < 100 & map_image(:,:,2) > 150 & map_image(:,:,3) < 100); % Example: Green shades
meta_sediments_mask = (map_image(:,:,1) < 100 & map_image(:,:,2) < 100 & map_image(:,:,3) > 150); % Example: Blue shades
whos
nnz(ryolite_mask) %<<< Your masks are all zeros, so you get no colors
nnz(andesite_mask)
nnz(meta_sediments_mask)
% Create a copy of the map for coloring
colored_map = map_image;
% Apply colors to the masks
% Rhyolite - Red
colored_map(:,:,1) = colored_map(:,:,1) + uint8(ryolite_mask) * 255; % Red channel
colored_map(:,:,2) = colored_map(:,:,2) - uint8(ryolite_mask) * 255; % Green channel
colored_map(:,:,3) = colored_map(:,:,3) - uint8(ryolite_mask) * 255; % Blue channel
% Andesite - Green
colored_map(:,:,1) = colored_map(:,:,1) - uint8(andesite_mask) * 255;
colored_map(:,:,2) = colored_map(:,:,2) + uint8(andesite_mask) * 255;
colored_map(:,:,3) = colored_map(:,:,3) - uint8(andesite_mask) * 255;
% Meta-sediments - Blue
colored_map(:,:,1) = colored_map(:,:,1) - uint8(meta_sediments_mask) * 255;
colored_map(:,:,2) = colored_map(:,:,2) - uint8(meta_sediments_mask) * 255;
colored_map(:,:,3) = colored_map(:,:,3) + uint8(meta_sediments_mask) * 255;
% Display the colored map
figure;
imshow(colored_map);
title('Colored Geological Map');
% Save the colored map
imwrite(colored_map, 'Colored_Geological_Map_Automatic.jpg');
0 件のコメント
Cris LaPierre
2025 年 1 月 20 日 15:01
編集済み: Cris LaPierre
2025 年 1 月 20 日 15:04
The reason your masks are all 0 is because all 3 channels have the same value. You can confirm this using the imageViewer app. Zoom in until you see the individual pixel values (or use the approach suggested in the comments provided in the script).

Your masks apply a different threshold value to each channel. Since the values are the same in all 3 channels, the result will always be zero. For example, consider your ryolite mask.
ryolite_mask = (...
map_image(:,:,1) > 200 & ...
map_image(:,:,2) < 100 & ...
map_image(:,:,3) < 100);
Since this image is 'colored' using textures rather that gray tones, I do not think this approach will produce your desired result.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で White についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!