Setting MATLAB's default colormap - matlab-figure

I am preparing some figures for a paper printed in black and white. I thought that easiest way to do so was to change the default colormap to gray. However I'm stuck with the following error:
set(0,'DefaultFigureColormap',gray);
Error using set
Value must be either:
an Mx3 array of type single or double in the range [0 1]
an Mx3 array of type uint8

You can use the built-in function rgb2gray to convert from RGB. There are other such alternatives mentioned in the Image Processing Toolbox.

Related

Error using imcontrast tool in MATLAB

I have a problem with imcontrast tool.
I read 2D dicom image, then convert it to 16bits(im2uint16) and perform filtration and windowing using imcontrast.
It shows me a warning message:
How Can I prevent then ?
How can I change data range in imtool ?
I would appreciate for any help please.
The [0,51156] is the range of the image data which change from image to image. [0, 65535] are the default color axis limits for uint16, which are outside the image data range, causing the re-adjust warning prompt. If you wish to silence the prompt you can manually set the color axis limits before calling imcontrast by:
caxis([double(min(min(Image))), double(max(max(Image)))]);
The conversion to double is to prevent a datatype mismatch. max() and min() return an uint16 value with uint16 data, which causes an another error down the line.

Matlab gui image incorrectly blue

I am creating a GUI containing an image using the following code:
try
Imagenamehere = imread('Imagenamehere.jpg');
axes(handles.Logo)
image(Imagenamehere)
set(gca,'xtick',[],'ytick',[])
catch
msgbox('Please download all contents from the zipped file into working directory.')
end
The image shows up but for some reason is completely coloured blue as if put through a blue filter. I don't think it would be wise to upload the image but it is a simple logo coloured black and white.
Anyone know what could be causing this?
Check the size, type (probably uint8) and range of your image. It sounds like for some reason your images are being displayed with colormap as jet (the default), and possibly also that your range is not what MATLAB expects (e.g. 0 to 1 not 0 to 255), resulting in all your values being relatively low (blue on the jet colormap).
"black and white" is just one way of interpreting an image file which contains only two colors. MATLAB makes several assumptions when you pass data into a display function like image. If you don't specify colormap and image data range, it will make a guess based off things like data type.
One possibility is that your logo file is an indexed image. In these cases you need to do:
[Imagenamehere map] = imread('Imagenamehere.jpg');
colormap(map);

Getting the standard deviation of an image in Julia

I'm using the Images package and I want to load in an image and get the mean and standard deviation of the pixels in r image.
I tried:
using Images, Color, FixedPointNumbers, ImageView, Testimages
img = testimage("mandril")
mean(data(img))
The mean worked fine, in fact in IJulia it displays the mean color of the image. However, when I tried to get the standard deviation of the image, I get:
std(data(img))
`varm` has no method matching varm(::Image{RGB{UfixedBase{Uint8,8}},2,Array{RGB{UfixedBase{Uint8,8}},2}}, ::RGB{Float32})
while loading In[66], in expression starting on line 1
in var at statistics.jl:162
How would one go about getting the standard deviation of the image?
You can use red, green and blue to extract the components of image,
and compute the standard deviation with std on the resulting matrices.
using Images
using TestImages
using Color
img = testimage("mandril")
data(img)
RGB(
std(red(img)),
std(green(img)),
std(blue(img))
)
# RGB{Float32}(0.22030124f0,0.18964756f0,0.24422659f0)
You could also build a 3-dimensional array with all the data,
with separate,
and apply std on the three 2-dimensional slices corresponding
to the three components, with mapslices.
vec( mapslices( std, separate(img), [1,2] ) )
If you want to figure out why mean(data(img)) works
and std(data(img)) does not (at least, currently),
you can check which method is called
with #which, and read the corresponding code, with #less.
#which mean(data(img))
# mean(A::AbstractArray{T,N}) at statistics.jl:17
#which std(data(img))
# std(A::AbstractArray{T,N}) at statistics.jl:204
#less mean(data(img))
#less std(data(img))
There are (at least) two problems: first, sqrt is not defined for colours,
second, some of the code in std assumes that the mean is a Number.

function imshow() in matlab for class double

Why is an image of class type double seen completely white when the function imshow is used in matlab?This seems to be the case with every image
By default, imshow expects images of type double to be in the range [0,1].
As a solution, you can do the following:
imshow(img, [])
This is equivalent to:
imshow(img, 'DisplayRange',[min(img(:)) max(img(:))])
Alternatively you can manually normalize the image to the expected [0,1] range.
You can use im2double:
imshow(im2double(I))

How to convert html color names into RGB values in Ruby?

I know there is a gem called Color. I installed it.
But for the life of me, I can't figure out how to use the thing.
I just want to convert a color name into its RGB values, if possible without copying the whole color table into my code.
I want to be able to convert something like red or Navy into three numeric values.
require 'color/css'
red_code = Color::CSS["red"].html
#=> "#ff0000"
Old question, but I just came across this gem in a current project and had to do the same. I needed RBG values like OP asked for and so I used the css_rbg instance method similar to how tokland produced the hex value with the html instance method.
require 'color/css'
red_code = Color::CSS["red"].css_rgb
#=> "rgb(100.00%, 0.00%, 0.00%)"
Html colours are expressed as an Hexadecimal colour, and it turns out that a RGB colour is not more than a Hexadecimal expression of the colour so:
#ff0000 = r:255 g:0 b:0

Resources